-
Notifications
You must be signed in to change notification settings - Fork 0
#2 #3 #5 Assignments for php java #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
4b97dbb
d73d0a3
bb9794f
871f4e8
99ff64e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||
| } | ||
|
|
||
| } |
This file was deleted.
This file was deleted.
| 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; | ||
|
|
||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| */ | ||
| userInput = new Scanner(System.in); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Executer.chosenOption = userInput.nextInt(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| TaskSwitcher taskSwitcher = new TaskSwitcher(Executer.chosenOption); | ||
| taskSwitcher.switchAndRun(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.lftechnology.runner; | ||
|
|
||
| public class Menu { | ||
|
|
||
| public Menu() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| } | ||
|
|
||
| public void showmenu() { | ||
| System.out.println("Please hit the options below to play with us"); | ||
| System.out.println("Options Program"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("1 Salutation"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("2 Multiplier"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("3 Palindrome"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("0 Exit"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("......................"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.print("Press the option above to continue: "); | ||
| Executer executor = new Executer(); | ||
| executor.askForInputAndRun(); | ||
| } | ||
|
|
||
| } | ||
| 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: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| System.out.println("You are exiting the program now..."); | ||
| System.out.println("Exited"); | ||
| System.exit(0); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| default: | ||
| System.out.println("Invalid grade"); | ||
| } | ||
| System.out.println("Program Completed."); | ||
| Menu menu = new Menu(); | ||
| menu.showmenu(); | ||
| } | ||
| } | ||
This file was deleted.




There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.