I'm trying to make this calculator I can make it using 4 methods, one for addition one for subtraction and ..... but I want to make it a simple as possible. how can I perform the 4 main actions using one method and then call it in static main?
package com.company;
import java.util.Scanner;
public class Main {
final static String first = "first number: ";
final static String sec = "second number: ";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("what do you want to use? (multiply (input *), divide (input /), subtract (input -), addition (input +)");
String input = scanner.nextLine();
double answer = calculation(input); ----------------------
System.out.println(answer);
}
public static double calculation(double element){ ----------------------
Scanner scanner = new Scanner(System.in);
System.out.println(first);
double firstInput = scanner.nextDouble();
System.out.println(sec);
double secInput = scanner.nextDouble();
return firstInput element secInput; ----------------------
}
}
can I change the element to (+ - * /) ?
(the ------------------ part is were I have a problem)