123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
-
- import java.util.*;
- class Calculator{
- public static void main(String args[]){
-
- String toDo; //what the user wants to do
- double num1 = 0; //The user's first input
- double num2 = 0; //The user's second input
- double result = 0; //The user's answer
- boolean off = false; //The user typed quit, becomes true
- double memory;
- boolean error = false;
- MathMethods calc = new MathMethods();
-
- while (off == false){
- Scanner input1 = new Scanner(System.in);
- System.out.println("What do you want to do?");
- toDo = input1.nextLine();
-
- if (toDo.equals("quit")){
- off = true;
- System.out.println("Goodbye!!");
-
- } else {
-
- //System.out.println("toDO is: " + toDo);
-
- System.out.println(toDo + " -- Enter first number:");
- num1 = input1.nextDouble();
- //System.out.println("num1 is: " + num1);
-
- switch (toDo){
- case "add":
- case "subtract":
- case "multiply":
- case "divide":
- case "exponent":
- System.out.println(toDo + " -- Enter second number:");
- num2 = input1.nextDouble();
- //System.out.println("num2 is: " + num2);
-
- }
-
- switch (toDo) {
- case "add":
- result = calc.add(num1, num2);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "subtract":
- result = calc.subtract(num1, num2);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "multiply":
- result = calc.multiply(num1, num2);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "divide":
- result = calc.divide(num1, num2);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "exponent":
- result = calc.exponent(num1, num2);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "cosine":
- result = calc.cosine(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "inverse cosine":
- result = calc.invCosine(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "square root":
- result = calc.squareRoot(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "invert":
- result = calc.invert(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "sine":
- result = calc.sin(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "inverse sine":
- result = calc.iSin(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "degree to radian":
- result = calc.degToRad(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "radian to degree":
- result = calc.radToDeg(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
- }
- }
-
- }
- }
- }
|