Explorar el Código

Updated console and methods connecting to it

Trinh Tong hace 6 años
padre
commit
a38b96c2df
Se han modificado 2 ficheros con 64 adiciones y 66 borrados
  1. 46
    6
      Console.java
  2. 18
    60
      Trig.java

+ 46
- 6
Console.java Ver fichero

@@ -32,6 +32,7 @@ public class Console {
32 32
             menuInput = Console.getStringInput("Enter the calculator you want to use by key. (ie. 1 for basic, etc.)");
33 33
 
34 34
             switch (menuInput) {
35
+                // Basic Calculator
35 36
                 case "1":
36 37
                 basicCalc.Basic();
37 38
 
@@ -62,9 +63,9 @@ public class Console {
62 63
                         basicCalc.getQuotient(basicInput1, basicInput2);
63 64
                     }
64 65
                 } else if (basicMode.equals("5")) {
65
-                    
66
+
66 67
                     break;
67
-                    
68
+
68 69
                 } else {
69 70
                     //error if wrong input was entered
70 71
                     answer = Double.NaN;
@@ -103,11 +104,50 @@ public class Console {
103 104
                     memory.memoryMenu();
104 105
                 } else if (sciMenuInput.equals("3")) {
105 106
                     // To Trig Menu
106
-                    answer = trigMenu.TrigFunctions();
107
-                    Console.println(Double.toString(answer));
108
-                    String response = Console.getStringInput("Would you like to convert your answer from radian to degrees? Y or N").toLowerCase();
107
+                    trigMenu.trigFunctions();
108
+                    String mode = Console.getStringInput("Enter trignometric function by key: (ie. 1 for sin)");
109
+
110
+                    double trigInput = Console.getDoubleInput("Enter the input for the trignometric function: ");
111
+
112
+                    if (mode.equals("1")) {
113
+                        answer = trigMenu.calcSin(trigInput);
114
+
115
+                        //COS
116
+                    } else if (mode.equals("2")) {
117
+                        answer = trigMenu.calcCos(trigInput);
118
+
119
+                        //TAN
120
+                    } else if (mode.equals("3")) {
121
+                        answer = trigMenu.calcTan(trigInput);
122
+
123
+                        //ARCSIN
124
+                    } else if (mode.equals("4")) {
125
+                        answer = trigMenu.calcArcsin(trigInput);
126
+
127
+                        //ARCCOS
128
+                    } else if (mode.equals("5")) {
129
+                        answer = trigMenu.calcArccos(trigInput);
130
+
131
+                        //ARCTAN
132
+                    } else if (mode.equals("6")) {
133
+                        answer = trigMenu.calcArctan(trigInput);
134
+
135
+                    } else if (mode.equals("7")) {
136
+                        break;
137
+
138
+                    } else {
139
+                        //Error message if input does not match options, loops back to the top so they can try again.
140
+                        answer = Double.NaN;
141
+
142
+                    }
143
+
144
+                    String trigAnswer = Double.toString(answer);
145
+                    Console.println(trigAnswer);
146
+
147
+                    String trigDefRad =  Console.getStringInput("Do you want to convert your answer from radians to degrees?"
148
+                            + "\nEnter Y or N").toLowerCase();
109 149
 
110
-                    if (response.equals("y") ) {
150
+                    if (trigDefRad.equals("y") ) {
111 151
                         trigMenu.toDegrees(answer);
112 152
                     }
113 153
                     break;

+ 18
- 60
Trig.java Ver fichero

@@ -1,5 +1,4 @@
1 1
 
2
-
3 2
 /**
4 3
  * Trig class to perform trig function for our Graphing Calculator
5 4
  * (sin, cos, tan, inverses, degree to radian)
@@ -11,97 +10,57 @@ public class Trig
11 10
     double input = 0.0;
12 11
     double answer;
13 12
     String operation = "";
14
-    
15
-    public double TrigFunctions()
13
+
14
+    public void trigFunctions()
16 15
     {
17
-        //a check to make sure user input is valid
18
-        boolean validInput = false;
19
-        
20
-        //Get input of type of function
21
-        operation = Console.getStringInput("Which trignometric function would you like to run? \n sin, cos, tan, arcsin, arccos, arctan");
22
-        operation = operation.toLowerCase();
23
-        
24
-        //Get input of number
25
-        input = Console.getDoubleInput("What number would you like to find the " + operation + " of?");
26
-        
27
-        //Do the math depending on the input.
28
-        //SIN
29
-        if (operation.equals("sin")) {
30
-            calcSin(input);
31
-        
32
-            
33
-        //COS
34
-        } else if (operation.equals("cos")) {
35
-            calcCos(input);
36
-        
37
-            
38
-        //TAN
39
-        } else if (operation.equals("tan")) {
40
-            calcTan(input);
41
-        
42
-            
43
-        //ARCSIN
44
-        } else if (operation.equals("arcsin")) {
45
-            calcArcsin(input);
46
-        
47
-            
48
-        //ARCCOS
49
-        } else if (operation.equals("arccos")) {
50
-            calcArccos(input);
51
-        
52
-            
53
-        //ARCTAN
54
-        } else if (operation.equals("arctan")) {
55
-            calcArctan(input);
16
+        Console.println("Trigonometry Calculator Options" 
17
+            + "\n1: sin"
18
+            + "\n2: cosin"
19
+            + "\n3: tan"
20
+            + "\n4: arcsin"
21
+            + "\n5: arccosin"
22
+            + "\n6: arctan"
23
+            + "\n7: Cancel - returns to Main Menu");   
24
+
56 25
         
57
-           
58
-        //Error message if input does not match options, loops back to the top so they can try again.
59
-        } else {
60
-            answer = Double.NaN;
61
-            
62 26
     }
63
-        return answer;
64
-       
65
-    
66
-}
67
-    
68
-    
27
+
69 28
     //Sin method
70 29
     public double calcSin(double x) {
71 30
         answer = Math.sin(x);
72 31
         return answer;
73 32
     }
74
-    
33
+
75 34
     //Cos method
76 35
     public double calcCos(double x) {
77 36
         answer = Math.cos(x);
78 37
         return answer;
79 38
     }
80
-    
39
+
81 40
     //Tan method
82 41
     public double calcTan(double x) {
83 42
         answer = Math.tan(x);
84 43
         return answer;
85 44
     }
86
-    
45
+
87 46
     //Arcsin method
88 47
     public double calcArcsin(double x) {
89 48
         answer = Math.asin(x);
90 49
         return answer;
91 50
     }
92
-    
51
+
93 52
     //Arccos method
94 53
     public double calcArccos(double x) {
95 54
         answer = Math.acos(x);
96 55
         return answer;
97 56
     }
98
-    
57
+
99 58
     //Arctan method
100 59
     public double calcArctan(double x) {
101 60
         answer = Math.atan(x);
102 61
         return answer;
103 62
     }
104
-    
63
+
105 64
     //Converting from Radians to Degrees
106 65
     public double toDegrees(double answer) 
107 66
     {
@@ -112,4 +71,3 @@ public class Trig
112 71
     }
113 72
 }
114 73
 
115
-