Przeglądaj źródła

Updated console and methods connecting to it

Trinh Tong 6 lat temu
rodzic
commit
260e7ec856
2 zmienionych plików z 12 dodań i 44 usunięć
  1. 8
    41
      Basic.java
  2. 4
    3
      Console.java

+ 8
- 41
Basic.java Wyświetl plik

@@ -13,50 +13,17 @@ public class Basic
13 13
     String operation = "";
14 14
     double answer;
15 15
     
16
-    public double Basic()
16
+    public void Basic()
17 17
     {
18
-        
19
-        //Get input of first number
20
-        input1 = Console.getDoubleInput("What is the first number?");
21
-            
22
-        //Get input of operation
23
-        operation = Console.getStringInput("Which operation would you like to perform? \n +, -, *, /");
24
-  
25
-        //Get input of second number
26
-        input2 = Console.getDoubleInput("What is the second number?");
27
-        
28
-        //Do the math depending on the inputs.
29
-        //addition
30
-        if (operation.equals("+")) {
31
-            getSum(input1, input2);
32
-        
33
-        //subtraction    
34
-        } else if (operation.equals("-")) {
35
-            getDiff(input1, input2);
36
-        
37
-        //multiplication
38
-        } else if (operation.equals("*")) {
39
-            getProduct(input1, input2);
40
-            
41
-        //division    
42
-        } else if (operation.equals("/")) {
43
-            //error message when trying to divide by 0.
44
-            if (input2 == 0) {
45
-                Console.println("undefined");
46
-                //Insert return to main menu.
47
-            } else {
48
-            getQuotient(input1, input2);
49
-        }
50
-        } else {
51
-            //error if wrong input was entered
52
-            answer = Double.NaN;
53
-            
54
-            
18
+        Console.println("Basic Calculator Options" 
19
+                         + "\n+: Addition"
20
+                         + "\n-: Subtraction"
21
+                         + "\n*: Multiplication"
22
+                         + "\n/: Division"
23
+                         + "\n5: Cancel - returns to Main Menu");        
24
+
55 25
     }
56
-        
57
-        return answer;
58 26
 
59
-}
60 27
     //addition method
61 28
     public double getSum(double x, double y) {
62 29
         answer = x + y;

+ 4
- 3
Console.java Wyświetl plik

@@ -61,17 +61,18 @@ public class Console {
61 61
                     } else {
62 62
                         basicCalc.getQuotient(basicInput1, basicInput2);
63 63
                     }
64
+                } else if (basicMode.equals("5")) {
65
+                    
66
+                    break;
67
+                    
64 68
                 } else {
65 69
                     //error if wrong input was entered
66 70
                     answer = Double.NaN;
67 71
                     Console.println("Invalid Input");
68 72
                 }
69 73
 
70
-                
71 74
                 break;
72
-
73 75
                 case "2":
74
-
75 76
                 // Sends to Advanced Calculator Functions
76 77
                 break;
77 78