Author Topic: Java Calculator  (Read 1671 times)

Hey!
I made a calculator with Java.
Code: [Select]
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

lol 15 views and no reaction :/

I don't know anything about Java, but I will give this 10/10 and a :cookie:
                      ^
                   much
:)
« Last Edit: December 20, 2010, 06:15:17 PM by CookieDough »

I don't know anything about Java, but I will give this 10/10 and a :cookie:
                      ^
                   much
:)

cookiedough is dough of a cookie


It'd be nice to know how to use it.

It'd be nice to know how to use it.

Well, I don't know how to package it so other people can use it. :( I'm still learning this :)

"devide" lol

Yeah a fail there, but it wont hurt the code :)

Well, I don't know how to package it so other people can use it. :( I'm still learning this :)

Save it as a .java file and use a script compiler to compile it into scripts?

Save it as a .java file and use a script compiler to compile it into scripts?

Well, eclipse (a program that I use to Code) saves it always as .java but, I don't understand what you mean with a script compiler :o