123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- import java.util.*;
-
- /**
- * Write a description of class Calculator here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
-
- 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.next();
-
- if (toDo.equalsIgnoreCase("quit")){
- off = true;
- System.out.println("Goodbye!!");
-
- } else if(toDo.equalsIgnoreCase("memory")){
- System.out.println("Read, Change or Clear?");
- String mem = input1.next();
- switch(mem) {
- case "Read" :
- result = Memory.memRead();
- Memory.printAns(String.valueOf(result));
- break;
-
- case "Change" :
- System.out.println("Enter number:");
- num1 = input1.nextDouble();
- result = Memory.memUpdate(num1);
- Memory.printAns(String.valueOf(result));
- break;
-
- case "Clear" :
- result = Memory.memClear();
- Memory.printAns(String.valueOf(result));
- break;
-
- }
- }
-
-
- 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;
-
- case "square":
- result = calc.square(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "inverse":
- result = calc.inverse(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "tangent":
- result = calc.tangent(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- case "inverse tangent":
- result = calc.iTan(num1);
- memory = result;
- calc.printAns(String.valueOf(result));
- break;
-
- }
- }
- }
- }
- }
-
- // /**
- // * Created by leon on 2/9/18.
- // */
- // public class Console {
- // Calculator calc = new Calculator();
-
- // public static void print(String output, Object... args) {
- // System.out.printf(output, args);
- // }
-
- // public static void println(String output, Object... args) {
- // print(output + "\n", args);
- // }
-
- // public static String getMethod() {
- // Scanner scanner = new Scanner(System.in);
- // String userInput = scanner.nextLine();
- // return userInput;
- // }
-
- // public static String switchStatment() {
- // Scanner scanner = new Scanner(System.in);
- // String ultimateAnswer = "";
- // Boolean turnOff = false;
-
- // switch (getMethod()) {
- // case "add" :
- // System.out.println("Enter your numbers:");
- // double userInput = scanner.nextDouble();
- // double nextInput = scanner.nextDouble();
-
- // double answer = Calculator.add(userInput, nextInput);
- // ultimateAnswer = Double.toString(answer);
- // return Double.toString(answer);
-
- // case "subtract" :
- // System.out.println("Enter your numbers:");
- // userInput = scanner.nextDouble();
- // nextInput = scanner.nextDouble();
-
- // answer = Calculator.subtract(userInput, nextInput);
- // ultimateAnswer = Double.toString(answer);
- // return ultimateAnswer;
-
- // case "multiply" :
- // System.out.println("Enter your numbers:");
- // userInput = scanner.nextDouble();
- // nextInput = scanner.nextDouble();
-
- // answer = Calculator.multiply(userInput, nextInput);
- // ultimateAnswer = Double.toString(answer);
- // return ultimateAnswer;
-
- // case "divide" :
- // System.out.println("Enter your numbers:");
- // userInput = scanner.nextDouble();
- // nextInput = scanner.nextDouble();
-
- // answer = Calculator.divide(userInput, nextInput);
- // ultimateAnswer = Double.toString(answer);
- // return ultimateAnswer;
-
- // case "Square Root" :
-
- // }
- // return ultimateAnswer;
- // }
-
- // /*public static String getStringInput(String prompt) {
- // Scanner scanner = new Scanner(System.in);
- // println(prompt);
- // String userInput = scanner.nextLine();
- // return userInput;
- // }
-
- // public static Integer getIntegerInput(String prompt) {
- // Scanner scanner = new Scanner(System.in);
- // println(prompt);
- // int userInput = scanner.nextInt();
- // return null;
- // }
-
- // public static Double getDoubleInput(String prompt) {
- // Scanner scanner = new Scanner(System.in);
- // println(prompt);
- // double userInput = scanner.nextDouble();
- // double nextInput = scanner.nextDouble();
- // double answer = Calculator.add(userInput, nextInput);
- // return answer;
- // }*/
-
- // }
|