-
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 all commits
4b97dbb
d73d0a3
bb9794f
871f4e8
99ff64e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.lftechnology.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"); | ||
|
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. |
||
| scanner = new Scanner(System.in); | ||
| this.numberOfMultiple = scanner.nextInt(); | ||
| System.out.println("->Please Enter First 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. |
||
| this.firstMultiplier = scanner.nextInt(); | ||
| System.out.println("->Please Enter Second 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. |
||
| this.secondMultiplier = scanner.nextInt(); | ||
| int sum = calculateMultiplier(); | ||
| System.out.println("Sum of multiple by " + this.firstMultiplier + " and " + this.secondMultiplier + " below " | ||
|
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. |
||
| + this.numberOfMultiple + "=" + sum); | ||
| 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"); | ||
|
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("->Executing 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. |
||
|
|
||
| } | ||
|
|
||
| public void endRun() { | ||
| 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.println("-----------------------------------------\n\n"); | ||
|
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. |
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.lftechnology.programs; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class PalindromeProgram { | ||
|
|
||
| private String number; | ||
| private Scanner scanner; | ||
|
|
||
| public PalindromeProgram() { | ||
|
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 run() { | ||
| this.initiateRun(); | ||
| System.out.println("->Please Enter the Number of 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. |
||
| scanner = new Scanner(System.in); | ||
| this.number = scanner.nextLine(); | ||
| Boolean isPalindrome = this.isPalindrome(); | ||
| if (isPalindrome == true) { | ||
|
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("The number is a palindrome number"); | ||
|
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. |
||
| } else { | ||
| System.out.println("The number is not a palindrome number"); | ||
|
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. |
||
| } | ||
| 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)) | ||
|
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. |
||
| return true; | ||
| else | ||
| return false; | ||
|
|
||
| } | ||
|
|
||
| public void initiateRun() { | ||
| System.out.println("\n"); | ||
|
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("->Executing Palindrome 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. |
||
|
|
||
| } | ||
|
|
||
| public void endRun() { | ||
| 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.println("-----------------------------------------\n\n"); | ||
|
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. |
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.lftechnology.programs; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class SalutationProgram { | ||
|
|
||
| private Scanner fullNameWithSalutationInput; | ||
| private String fullNameWithSalutation; | ||
| private String salutation; | ||
|
|
||
| public SalutationProgram() { | ||
|
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 run() { | ||
| this.initiateRun(); | ||
| this.askForInput(); | ||
| if (this.fullNameWithSalutation.length() <= 0) { | ||
| System.out.println("->Input can't be empty! Enter again"); | ||
|
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. |
||
| this.askForInput(); | ||
| } | ||
| this.splitInput(); | ||
| System.out.println("Salutation = " + this.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("FullName = " + this.fullNameWithSalutation); | ||
|
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. |
||
| this.endRun(); | ||
| } | ||
|
|
||
| public void initiateRun() { | ||
| System.out.println("\n"); | ||
|
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("->Executing 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("->Please Enter Your Full Name with Salutation (e.g, Mr. John Doe)\n\n"); | ||
|
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 endRun() { | ||
| 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.println("-----------------------------------------\n\n"); | ||
|
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 splitInput() { | ||
| String[] splited = this.fullNameWithSalutation.split("\\s+"); | ||
| this.salutation = splited[1]; | ||
| } | ||
|
|
||
| public void askForInput() { | ||
| fullNameWithSalutationInput = new Scanner(System.in); | ||
| this.fullNameWithSalutation = fullNameWithSalutationInput.nextLine(); | ||
| } | ||
|
|
||
| } | ||
| 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; | ||
|
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 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"); | ||
|
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("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: "); | ||
|
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 executor = new Executer(); | ||
| executor.askForInputAndRun(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.lftechnology.runner; | ||
|
|
||
| import com.lftechnology.programs.MultiplierProgram; | ||
| import com.lftechnology.programs.PalindromeProgram; | ||
| import com.lftechnology.programs.SalutationProgram; | ||
|
|
||
| public class TaskSwitcher { | ||
|
|
||
| protected int chosenOption; | ||
|
|
||
| public TaskSwitcher(int option) { | ||
| this.chosenOption = option; | ||
| } | ||
|
|
||
| public void switchAndRun() { | ||
| Menu menu = new Menu(); | ||
| 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..."); | ||
|
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("->Exited"); | ||
|
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.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 Input"); | ||
|
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("\n"); | ||
|
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. |
||
| menu.showmenu(); | ||
| } | ||
| 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.