I made a pretty advanced calculator using TADA Java!
I really love Java it is such an awesome programming language.
Java > Torque EngineCode:
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 /");
System.out.println("Type: 5 for ^");
System.out.println("Type: 6 for Squareroot");
System.out.println("Type: 7 for Tables");
System.out.println("Type: 8 for Average");
System.out.println("Type: 9 for Compound interest");
Catch = input.nextInt();
switch(Catch){
case 1:
CalculatorObject.plus();
break;
case 2:
CalculatorObject.min();
break;
case 3:
CalculatorObject.times();
break;
case 4:
CalculatorObject.divide();
break;
case 5:
CalculatorObject.Power();
break;
case 6:
CalculatorObject.Squareroot();
break;
case 7:
CalculatorObject.Tables();
break;
case 8:
CalculatorObject.Average();
break;
case 9:
CalculatorObject.rente();
break;
default:
System.out.println("Syntax error.");
}
}
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: "+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: "+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: "+total);
}
public void divide(){
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: "+total);
}
public void Power(){
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 = Math.pow(printy, printy2);
System.out.print("Answer: "+total);
}
public void Squareroot(){
Scanner input = new Scanner(System.in);
double printy;
double total;
System.out.println("Type your number:");
printy = input.nextDouble();
total = Math.sqrt(printy);
System.out.print("Answer: "+total);
}
public void Tables(){
Scanner input = new Scanner(System.in);
System.out.println("Type here what table you want to show:");
int tafel = input.nextInt();
System.out.println("Som\tAnswer");
int bucky[] = {1, tafel * 1, tafel * 2, tafel * 3, tafel * 4, tafel * 5, tafel * 6, tafel * 7, tafel * 8, tafel * 9, tafel * 10};
for(int counter=1;counter<=10;counter++){
System.out.println(counter + "x" + tafel + "=" + "\t" + bucky[counter] );
}
}
public void Average(){
Scanner input = new Scanner(System.in);
double total = 0;
double grade;
double average;
double counter = 0;
double AC = 0;
System.out.println("Type here how from many numbers you want the average:");
AC = input.nextDouble();
System.out.println("Type here the numbers:");
while (counter < AC){
grade = input.nextDouble();
total = total + grade;
counter++;
}
average = total/counter;
System.out.println("The average is: "+ average);
}
public void rente(){
Scanner input = new Scanner(System.in);
double amount;
double principal;
double rate;
int Timeinput;
System.out.println("Type the amount:");
principal = input.nextDouble();
System.out.println("Type the rate:");
rate = input.nextDouble();
System.out.println("Type the the amount of days/weeks/months/years ETC:");
Timeinput = input.nextInt();
System.out.println("Time \t Amount");
for(int time=1;time<=Timeinput;time++){
amount=principal*Math.pow(1 + rate, time);
System.out.println(time + "\t"+ amount);
}
}
}
Code length: 185
Example:
----------------------------------------------------------------------------
Welcome to the calculator!
Type: 1 for +
Type: 2 for -
Type: 3 for *
Type: 4 for /
Type: 5 for ^
Type: 6 for Squareroot
Type: 7 for Tables
Type: 8 for Average
Type: 9 for Compound interest
6
Type your number:
16
Answer: 4.0
----------------------------------------------------------------------------
FAQ:
Q: "Why the **** would you build this?"
A: "Because I see how powerfull Java is and I love the way how they use Methods (= Functions), I am only building this to practise Java basics, my goal is building a nice game.

"
Q: "What do the other functions do?"
A: "That is not that hard to find in the code, try using your brains."
Q: "You got aids."
A: "That is not even a question, but no."
Q: "Why do you prefer Java?"
A: "Well I am made for it, my birth date was 1996, and in that year the first Java version came out :). But yes that coincidence doesn't say anything but I prefer the way how the use if statements and Methods."
Discuss.