Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
#2 #3 #5 Assignments for php java
  • Loading branch information
achyutddahal committed May 16, 2016
commit 4b97dbbeb7f0c90e3611171ac7f6ac956b76f3ae
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.lftechnology.com.programs;

import java.util.Scanner;

public class MultiplierProgram {

private int numberOfMultiple;
private int firstMultiplier;
private int secondMultiplier;
private Scanner scanner;

public MultiplierProgram() {

}

public void run() {
this.initiateRun();
System.out.println("Please Enter the Number of Multiplier");
scanner = new Scanner(System.in);
this.numberOfMultiple = scanner.nextInt();
System.out.println("Please Enter First Multiplier");
this.firstMultiplier = scanner.nextInt();
System.out.println("Please Enter Second Multiplier");
this.secondMultiplier = scanner.nextInt();
int sum = calculateMultiplier();
System.out.println("Sum of multiple by " + this.firstMultiplier + " and " + this.secondMultiplier + " below "
+ this.numberOfMultiple + "=" + sum);
System.out.println("Executing Multiplier");
this.endRun();
}

public int calculateMultiplier() {

int sum = 0;
for (int i = 0; i < this.numberOfMultiple; i++) {
if ((i % this.firstMultiplier) == 0 || (i % this.secondMultiplier) == 0) {
sum += i;
}
}
return sum;
}

public void initiateRun() {
System.out.println("\n");
System.out.println("Executing Multiplier");

}

public void endRun() {
System.out.println("-----------------------------------------");
System.out.println("-----------------------------------------\n\n");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.lftechnology.com.programs;

import java.util.Scanner;

public class PalindromeProgram {

private String number;
private Scanner scanner;

public PalindromeProgram() {

}

public void run() {
this.initiateRun();
System.out.println("Please Enter the Number of Multiplier");
scanner = new Scanner(System.in);
this.number = scanner.nextLine();
Boolean isPalindrome = this.isPalindrome();
if (isPalindrome == true) {
System.out.println("The number is a palindrome number");
} else {
System.out.println("The number is not a palindrome number");
}
this.endRun();
}

public Boolean isPalindrome() {
String reverse = "";
int length = this.number.length();
for (int i = length - 1; i >= 0; i--)
reverse = reverse + this.number.charAt(i);

if (this.number.equals(reverse))
return true;
else
return false;

}

public void initiateRun() {
System.out.println("\n");
System.out.println("Executing Palindrome Program");

}

public void endRun() {
System.out.println("-----------------------------------------");
System.out.println("-----------------------------------------\n\n");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.lftechnology.com.programs;

import java.util.Scanner;

public class SalutationProgram {

private Scanner fullNameWithSalutationInput;
private String fullNameWithSalutation;
private String salutation;

public SalutationProgram() {

}

public void run() {
this.initiateRun();
this.askForInput();
if (this.fullNameWithSalutation.length() <= 0) {
System.out.println("Input can't be empty! Enter again");
this.askForInput();
}
this.splitInput();
System.out.println("Salutation = " + this.salutation);
System.out.println("FullName = " + this.fullNameWithSalutation);
this.endRun();
}

public void initiateRun() {
System.out.println("\n");
System.out.println("Executing Salutation");
System.out.println("Please Enter Your Full Name with Salutation (e.g, Mr. John Doe\n\n");
}

public void endRun() {
System.out.println("-----------------------------------------");
System.out.println("-----------------------------------------\n\n");
}

public void splitInput() {
String[] splited = this.fullNameWithSalutation.split("\\s+");
this.salutation = splited[1];
}

public void askForInput() {
fullNameWithSalutationInput = new Scanner(System.in);
this.fullNameWithSalutation = fullNameWithSalutationInput.nextLine();
}

}
15 changes: 0 additions & 15 deletions achyut/src/main/java/com/lftechnology/one/DefaultTest.java

This file was deleted.

10 changes: 0 additions & 10 deletions achyut/src/main/java/com/lftechnology/one/Main.java

This file was deleted.

25 changes: 25 additions & 0 deletions achyut/src/main/java/com/lftechnology/runner/Executer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lftechnology.runner;

import java.util.Scanner;

public class Executer {

private static Scanner userInput;
public static int chosenOption;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Make this "public static chosenOption" field final rule
MAJOR Make chosenOption a static final constant or non-public and provide accessors if needed. rule


public static void main(String[] args) {
Menu menu = new Menu();
menu.showmenu();
}

public void askForInputAndRun() {
/**
* @todo Check if user input is empty in all the subsequent classes
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO Complete the task associated to this TODO comment. rule

*/
userInput = new Scanner(System.in);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Make the enclosing method "static" or remove this set. rule

Executer.chosenOption = userInput.nextInt();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Make the enclosing method "static" or remove this set. rule

TaskSwitcher taskSwitcher = new TaskSwitcher(Executer.chosenOption);
taskSwitcher.switchAndRun();
}

}
22 changes: 22 additions & 0 deletions achyut/src/main/java/com/lftechnology/runner/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lftechnology.runner;

public class Menu {

public Menu() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation. rule


}

public void showmenu() {
System.out.println("Please hit the options below to play with us");
System.out.println("Options Program");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.println("1 Salutation");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.println("2 Multiplier");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.println("3 Palindrome");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.println("0 Exit");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.println("......................");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Replace this usage of System.out or System.err by a logger. rule

System.out.print("Press the option above to continue: ");
Executer executor = new Executer();
executor.askForInputAndRun();
}

}
42 changes: 42 additions & 0 deletions achyut/src/main/java/com/lftechnology/runner/TaskSwitcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.lftechnology.runner;

import com.lftechnology.com.programs.MultiplierProgram;
import com.lftechnology.com.programs.PalindromeProgram;
import com.lftechnology.com.programs.SalutationProgram;

public class TaskSwitcher {

protected int chosenOption;

public TaskSwitcher(int option) {
this.chosenOption = option;

}

public void switchAndRun() {

switch (this.chosenOption) {
case 1:
SalutationProgram salutationProgram = new SalutationProgram();
salutationProgram.run();
break;
case 2:
MultiplierProgram multiplierProgram = new MultiplierProgram();
multiplierProgram.run();
break;
case 3:
PalindromeProgram palindromeProgram = new PalindromeProgram();
palindromeProgram.run();
break;
case 0:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR End this switch case with an unconditional break, return or throw statement. rule

System.out.println("You are exiting the program now...");
System.out.println("Exited");
System.exit(0);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this call to "exit" or ensure it is really required. rule

default:
System.out.println("Invalid grade");
}
System.out.println("Program Completed.");
Menu menu = new Menu();
menu.showmenu();
}
}
12 changes: 0 additions & 12 deletions achyut/src/main/java/com/lftechnology/two/PackageTwoMain.java

This file was deleted.