Przeglądaj źródła

Updated console and methods connecting to it

Trinh Tong 6 lat temu
rodzic
commit
95cd8c62f1
2 zmienionych plików z 20 dodań i 19 usunięć
  1. 4
    4
      Basic.java
  2. 16
    15
      Console.java

+ 4
- 4
Basic.java Wyświetl plik

@@ -16,10 +16,10 @@ public class Basic
16 16
     public void Basic()
17 17
     {
18 18
         Console.println("Basic Calculator Options" 
19
-                         + "\n+: Addition"
20
-                         + "\n-: Subtraction"
21
-                         + "\n*: Multiplication"
22
-                         + "\n/: Division"
19
+                         + "\n1: Addition"
20
+                         + "\n2: Subtraction"
21
+                         + "\n3: Multiplication"
22
+                         + "\n4: Division"
23 23
                          + "\n5: Cancel - returns to Main Menu");        
24 24
 
25 25
     }

+ 16
- 15
Console.java Wyświetl plik

@@ -35,32 +35,32 @@ public class Console {
35 35
                 // Basic Calculator
36 36
                 case "1":
37 37
                 basicCalc.Basic();
38
-
39
-                double basicInput1 = Console.getIntegerInput("Enter the first input: ");
40
-
38
+                
41 39
                 String basicMode = Console.getStringInput("Enter the mode: ");
40
+                double basicInput1 = Console.getDoubleInput("Enter the first input: ");
41
+                double basicInput2 = Console.getDoubleInput("Enter the second input: ");
42
+                
43
+                double basicAnswer = 0;
42 44
 
43
-                double basicInput2 = Console.getIntegerInput("Enter the second input: ");
44
-
45
-                if (basicMode.equals("+")) {
46
-                    basicCalc.getSum(basicInput1, basicInput2);
45
+                if (basicMode.equals("1")) {
46
+                    basicAnswer = basicCalc.getSum(basicInput1, basicInput2);
47 47
 
48 48
                     //subtraction    
49
-                } else if (basicMode.equals("-")) {
50
-                    basicCalc.getDiff(basicInput1, basicInput2);
49
+                } else if (basicMode.equals("2")) {
50
+                    basicAnswer = basicCalc.getDiff(basicInput1, basicInput2);
51 51
 
52 52
                     //multiplication
53
-                } else if (basicMode.equals("*")) {
54
-                    basicCalc.getProduct(basicInput1, basicInput2);
53
+                } else if (basicMode.equals("3")) {
54
+                    basicAnswer = basicCalc.getProduct(basicInput1, basicInput2);
55 55
 
56 56
                     //division    
57
-                } else if (basicMode.equals("/")) {
57
+                } else if (basicMode.equals("4")) {
58 58
                     //error message when trying to divide by 0.
59 59
                     if (basicInput2 == 0) {
60 60
                         Console.println("undefined");
61 61
                         //Insert return to main menu.
62 62
                     } else {
63
-                        basicCalc.getQuotient(basicInput1, basicInput2);
63
+                        basicAnswer = basicCalc.getQuotient(basicInput1, basicInput2);
64 64
                     }
65 65
                 } else if (basicMode.equals("5")) {
66 66
 
@@ -68,10 +68,11 @@ public class Console {
68 68
 
69 69
                 } else {
70 70
                     //error if wrong input was entered
71
-                    answer = Double.NaN;
71
+                    basicAnswer = Double.NaN;
72 72
                     Console.println("Invalid Input");
73 73
                 }
74
-
74
+                Console.println(Double.toString(basicAnswer));
75
+                
75 76
                 break;
76 77
                 case "2":
77 78
                 // Sends to Advanced Calculator Functions