Simple computer

public static void main(String[] args) {
System.out.println("Welcome to Simple Calculator");
System.out.println("Please enter the first number");
Scanner scanner = new Scanner(System.in);
int x = scanner. nextInt();
System.out.println("Please enter the second number");
int y = scanner.nextInt();
System.out.println("Please enter the symbol +-*/");
String code = scanner.next();
GuoruijiaTest test = new GuoruijiaTest();
test.setX(x);
test.setY (y); 
test.setCode(code); 
System.out.println("The figure is: "+test.setCode(code));

}



                            Test

public class XXXXXXX{

                private int x;
private int y;
private String code;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY () {
return y;
}
public void setY(int y) {
this.y = y;
}
public String getCode() {
return code;
}
public int setCode(String code) {
this.code = code;
switch (code) {
case "+":

return x+y; 
case "-":
return x-y;
case "summation" :
int sum = 0;
for (int i =0;i<y; i++){
sum+=i;

}

return sum;
case"*":
return x*y;

case "max":
return Math.max(x, y);
case "minimum":
return Math.min(x, y);
}
return 0;
}







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325785977&siteId=291194637