Hey!
I made a calculator with Java.
import java.util.Scanner;
class Calculator{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Calculator CalculatorObject = new Calculator();
int Catch;
System.out.println("Welcome to the calculator!");
System.out.println("Type: 1 for +");
System.out.println("Type: 2 for -");
System.out.println("Type: 3 for *");
System.out.println("Type: 4 for /");
Catch = input.nextInt();
switch(Catch){
case 1:
CalculatorObject.plus();
break;
case 2:
CalculatorObject.min();
break;
case 3:
CalculatorObject.times();
break;
case 4:
CalculatorObject.devide();
break;
}
}
public void plus(){
Scanner input = new Scanner(System.in);
double printy;
double printy2;
double total;
System.out.println("Type your first number:");
printy = input.nextDouble();
System.out.println("Type your second number:");
printy2 = input.nextDouble();
total = printy + printy2;
System.out.print("Answer: ");
System.out.print(total);
}
public void min(){
Scanner input = new Scanner(System.in);
double printy;
double printy2;
double total;
System.out.println("Type your first number:");
printy = input.nextDouble();
System.out.println("Type your second number:");
printy2 = input.nextDouble();
total = printy - printy2;
System.out.print("Answer: ");
System.out.print(total);
}
public void times(){
Scanner input = new Scanner(System.in);
double printy;
double printy2;
double total;
System.out.println("Type your first number:");
printy = input.nextDouble();
System.out.println("Type your second number:");
printy2 = input.nextDouble();
total = printy * printy2;
System.out.print("Answer: ");
System.out.print(total);
}
public void devide(){
Scanner input = new Scanner(System.in);
double printy;
double printy2;
double total;
System.out.println("Type your first number:");
printy = input.nextDouble();
System.out.println("Type your second number:");
printy2 = input.nextDouble();
total = printy / printy2;
System.out.print("Answer: ");
System.out.print(total);
}
}
Tell me what you think :)
You can rate x/10