I'm a noob to java and have to write this calculator. I'm learning JAVA for three weeks now but this is a number to big for me.
Sitting three days of thinking, reading, searching and of course trying to get it right I'm out of any ideas!
Most of the programm code have to be in methods and the main method should just start the programm!
My version works until the system asks you about the arithmetic operation. I got no Idea how to link the switch statement including the arithmetic operations to the scannermethod. So that one choose an arithmetic operation and the result comes out like this:
for example systemoutput: 12+12=24.
The task is to realize this using local variables as much as possible.
here is the code:
import java.util.Scanner;
public class calculator {
private int calculate;
private int x;
private int y;
private int result;
public static void input(){
Scanner sc = new Scanner(System.in);
System.out.print("Systemoutput: ");
System.out.print("insert an integral number:");
System.out.println("");
int x = Integer.parseInt(sc.next());
System.out.print("userinput: ");
System.out.println(x);
System.out.println("");
System.out.print("Systeoutput: ");
System.out.print("insert another integral number:");
System.out.println("");
int y = Integer.parseInt(sc.next());
System.out.print("userinput: ");
System.out.println(y);
System.out.println("");
System.out.print("Systemoutput: ");
System.out.println("please choose the arithmetic operation");
System.out.println(" (" + 1 + " = " + "addition; " + 2 + " = " + "subtraction;" + 3 + " = ");
System.out.print(" multiplication; " + 4 + " = " + "division; " + 5 + " = " + "percent; )" );
int calculate = Integer.parseInt(sc.next());
}
public static void calculate(){
public int getcalculate(){
switch (calculate) {
case 1 : result = x + y;
break;
case 2: result = x - y;
break;
case 3: result = x * y;
break;
case 4: result = x / y;
break;
case 5: result = x * 100 / y;
break;
}
}
}
public static void main (String[] args){
input();
calculate();
}
}
Maybe somebody can help.
Thanks in advance.
greets

Start a new topic
Add Reply




MultiQuote
| 


