BAEL-3506 - Refactoring.
This commit is contained in:
parent
c68e465576
commit
3bcb5ce809
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.maths.calculator.basic;
|
package com.baeldung.calculator.basic;
|
||||||
|
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
@ -7,19 +7,14 @@ public class BasicCalculatorIfElse {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
System.out.println("---------------------------------- \n" +
|
System.out.println("---------------------------------- \n" + "Welcome to Basic Calculator \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("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);
|
Scanner scanner = new Scanner(System.in);
|
||||||
try {
|
try {
|
||||||
System.out.println("Enter an operator: (+ OR - OR * OR /) ");
|
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 == '/')) {
|
if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) {
|
||||||
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.maths.calculator.basic;
|
package com.baeldung.calculator.basic;
|
||||||
|
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
@ -6,19 +6,14 @@ import java.util.Scanner;
|
||||||
public class BasicCalculatorSwitchCase {
|
public class BasicCalculatorSwitchCase {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
System.out.println("---------------------------------- \n"
|
System.out.println("---------------------------------- \n" + "Welcome to Basic Calculator \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("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);
|
Scanner scanner = new Scanner(System.in);
|
||||||
try {
|
try {
|
||||||
System.out.println("Enter an operator: (+ OR - OR * OR /) ");
|
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 == '/')) {
|
if (!(operation == '+' || operation == '-' || operation == '*' || operation == 'x' || operation == '/')) {
|
||||||
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
System.err.println("Invalid Operator. Please use only + or - or * or /");
|
||||||
|
@ -61,4 +56,3 @@ public class BasicCalculatorSwitchCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue