From 9f25b72ca447f7c59f84753be2f2568a745bd751 Mon Sep 17 00:00:00 2001 From: iamshwetabhardwaj <49850922+iamshwetabhardwaj@users.noreply.github.com> Date: Sun, 24 Nov 2019 22:54:06 +0530 Subject: [PATCH] BAEL-3506 - Refactoring. (#8238) * BAEL-3506 * BAEL-3506 * BAEL-3506 - Added java-math-2 to parent pom. * BAEL-3506 - Refactoring. --- .../basic/BasicCalculatorIfElse.java | 15 ++---- .../basic/BasicCalculatorSwitchCase.java | 54 +++++++++---------- 2 files changed, 29 insertions(+), 40 deletions(-) rename {java-math-2/src/main/java/com/baeldung/maths => core-java-modules/core-java-lang-math/src/main/java/com/baeldung}/calculator/basic/BasicCalculatorIfElse.java (82%) rename {java-math-2/src/main/java/com/baeldung/maths => core-java-modules/core-java-lang-math/src/main/java/com/baeldung}/calculator/basic/BasicCalculatorSwitchCase.java (50%) diff --git a/java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorIfElse.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorIfElse.java similarity index 82% rename from java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorIfElse.java rename to core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorIfElse.java index cad7bf0f13..87f274db51 100644 --- a/java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorIfElse.java +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorIfElse.java @@ -1,4 +1,4 @@ -package com.baeldung.maths.calculator.basic; +package com.baeldung.calculator.basic; import java.util.InputMismatchException; import java.util.Scanner; @@ -7,19 +7,14 @@ public class BasicCalculatorIfElse { public static void main(String[] args) { - System.out.println("---------------------------------- \n" + - "Welcome to Basic Calculator \n" + - "----------------------------------"); - System.out.println("Following operations are supported : \n" + - "1. Addition (+) \n" + - "2. Subtraction (-) \n" + - "3. Multiplication (* OR x) \n" + - "4. Division (/) \n"); + System.out.println("---------------------------------- \n" + "Welcome to Basic Calculator \n" + "----------------------------------"); + System.out.println("Following operations are supported : \n" + "1. Addition (+) \n" + "2. Subtraction (-) \n" + "3. Multiplication (* OR x) \n" + "4. Division (/) \n"); Scanner scanner = new Scanner(System.in); try { System.out.println("Enter an operator: (+ OR - OR * OR /) "); - char operation = scanner.next().charAt(0); + char operation = scanner.next() + .charAt(0); if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) { System.err.println("Invalid Operator. Please use only + or - or * or /"); diff --git a/java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorSwitchCase.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorSwitchCase.java similarity index 50% rename from java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorSwitchCase.java rename to core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorSwitchCase.java index f87437a967..82c181a0fe 100644 --- a/java-math-2/src/main/java/com/baeldung/maths/calculator/basic/BasicCalculatorSwitchCase.java +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/calculator/basic/BasicCalculatorSwitchCase.java @@ -1,4 +1,4 @@ -package com.baeldung.maths.calculator.basic; +package com.baeldung.calculator.basic; import java.util.InputMismatchException; import java.util.Scanner; @@ -6,19 +6,14 @@ import java.util.Scanner; public class BasicCalculatorSwitchCase { public static void main(String[] args) { - System.out.println("---------------------------------- \n" - + "Welcome to Basic Calculator \n" - + "----------------------------------"); - System.out.println("Following operations are supported : \n" + - "1. Addition (+) \n" + - "2. Subtraction (-) \n" + - "3. Multiplication (* OR x) \n" + - "4. Division (/) \n"); + System.out.println("---------------------------------- \n" + "Welcome to Basic Calculator \n" + "----------------------------------"); + System.out.println("Following operations are supported : \n" + "1. Addition (+) \n" + "2. Subtraction (-) \n" + "3. Multiplication (* OR x) \n" + "4. Division (/) \n"); Scanner scanner = new Scanner(System.in); try { System.out.println("Enter an operator: (+ OR - OR * OR /) "); - char operation = scanner.next().charAt(0); + char operation = scanner.next() + .charAt(0); if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) { System.err.println("Invalid Operator. Please use only + or - or * or /"); @@ -35,24 +30,24 @@ public class BasicCalculatorSwitchCase { } switch (operation) { - case '+': - System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); - break; - case '-': - System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); - break; - case '*': - System.out.println(num1 + " x " + num2 + " = " + (num1 * num2)); - break; - case 'x': - System.out.println(num1 + " x " + num2 + " = " + (num1 * num2)); - break; - case '/': - System.out.println(num1 + " / " + num2 + " = " + (num1 / num2)); - break; - default: - System.err.println("Invalid Operator Specified."); - break; + case '+': + System.out.println(num1 + " + " + num2 + " = " + (num1 + num2)); + break; + case '-': + System.out.println(num1 + " - " + num2 + " = " + (num1 - num2)); + break; + case '*': + System.out.println(num1 + " x " + num2 + " = " + (num1 * num2)); + break; + case 'x': + System.out.println(num1 + " x " + num2 + " = " + (num1 * num2)); + break; + case '/': + System.out.println(num1 + " / " + num2 + " = " + (num1 / num2)); + break; + default: + System.err.println("Invalid Operator Specified."); + break; } } catch (InputMismatchException exc) { System.err.println(exc.getMessage()); @@ -60,5 +55,4 @@ public class BasicCalculatorSwitchCase { scanner.close(); } } -} - +} \ No newline at end of file