浏览代码

EVERYTHING COMING TOGETHER

Trinh Tong 6 年前
父节点
当前提交
475d56ca95
共有 4 个文件被更改,包括 181 次插入99 次删除
  1. 60
    30
      Console.java
  2. 15
    39
      RealAdvanced.java
  3. 1
    6
      SwitchDisplay.java
  4. 105
    24
      package.bluej

+ 60
- 30
Console.java 查看文件

@@ -6,10 +6,11 @@ import java.util.Scanner;
6 6
 public class Console {
7 7
 
8 8
     public static void main(String[] args) {
9
-        double answer;
9
+
10 10
         // Create all instances of classes to be used for this program
11 11
         MainMenu mainMenu = new MainMenu();
12 12
         Basic basicCalc = new Basic();
13
+        RealAdvanced advCalc = new RealAdvanced();
13 14
         SciCalc scientificCalc = new SciCalc();
14 15
         MemoryFunc memory = new MemoryFunc();
15 16
         SwitchDisplay baseChange = new SwitchDisplay();
@@ -35,11 +36,11 @@ public class Console {
35 36
                 // Basic Calculator
36 37
                 case "1":
37 38
                 basicCalc.Basic();
38
-                
39
+
39 40
                 String basicMode = Console.getStringInput("Enter the mode: ");
40 41
                 double basicInput1 = Console.getDoubleInput("Enter the first input: ");
41 42
                 double basicInput2 = Console.getDoubleInput("Enter the second input: ");
42
-                
43
+
43 44
                 double basicAnswer = 0;
44 45
 
45 46
                 if (basicMode.equals("1")) {
@@ -72,10 +73,36 @@ public class Console {
72 73
                     Console.println("Invalid Input");
73 74
                 }
74 75
                 Console.println(Double.toString(basicAnswer));
75
-                
76
+
76 77
                 break;
77 78
                 case "2":
78
-                // Sends to Advanced Calculator Functions
79
+                advCalc.realAdvanced();
80
+                String mode = Console.getStringInput("Enter the mode: ");
81
+
82
+                double advInput1 = Console.getDoubleInput("Enter the first input: ");
83
+
84
+                double advAnswer = 0;
85
+
86
+                if (mode.equals("1")){
87
+                    advAnswer = advCalc.squared(advInput1);
88
+
89
+                }else if (mode.equals("2")){
90
+
91
+                    double advInput2 = Console.getDoubleInput("Enter the exponent value: ");
92
+                    advAnswer = advCalc.exponent(advInput1,advInput2);
93
+
94
+                }else if (mode.equals("3")){
95
+
96
+                    advAnswer = advCalc.inverse(advInput1);
97
+
98
+                }else if (mode.equals("4")){
99
+                    advAnswer = advCalc.opposite(advInput1);
100
+
101
+                }else {
102
+                    Console.println("Invalid input");
103
+                }
104
+
105
+                Console.println(Double.toString(advAnswer));
79 106
                 break;
80 107
 
81 108
                 case "3":
@@ -88,15 +115,17 @@ public class Console {
88 115
                 if (sciMenuInput.equals("1")) {
89 116
                     // Base Conversions
90 117
                     // while loop for display 
91
-                    String mode = "";
92
-                    while (!mode.equals("Invalid Input")) {
93
-                        baseChange.switchDisplay(); 
94
-                        mode = Console.getStringInput("Enter the desired display mode: ");
95
-                    }
118
+                    String baseMode = "";
119
+
120
+                    baseChange.switchDisplay(); 
121
+                    baseMode = Console.getStringInput("Enter the desired display mode: ");
96 122
 
97 123
                     int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
98
-                    baseChange.switchDisplayOutput(mode, userInput);
99 124
 
125
+                    String baseOutput = baseChange.switchDisplayOutput(baseMode, userInput);
126
+                    Console.println(baseOutput);
127
+
128
+                    break;
100 129
                     // display mode
101 130
                     // gets mode
102 131
                     // asks for input
@@ -106,50 +135,51 @@ public class Console {
106 135
                 } else if (sciMenuInput.equals("3")) {
107 136
                     // To Trig Menu
108 137
                     trigMenu.trigFunctions();
109
-                    String mode = Console.getStringInput("Enter trignometric function by key: (ie. 1 for sin)");
138
+                    String trigMode = Console.getStringInput("Enter trignometric function by key: (ie. 1 for sin)");
110 139
 
111 140
                     double trigInput = Console.getDoubleInput("Enter the input for the trignometric function: ");
112
-
113
-                    if (mode.equals("1")) {
114
-                        answer = trigMenu.calcSin(trigInput);
141
+                    double trigAnswer = 0;
142
+                    if (trigMode.equals("1")) {
143
+                        trigAnswer = trigMenu.calcSin(trigInput);
115 144
 
116 145
                         //COS
117
-                    } else if (mode.equals("2")) {
118
-                        answer = trigMenu.calcCos(trigInput);
146
+                    } else if (trigMode.equals("2")) {
147
+                        trigAnswer = trigMenu.calcCos(trigInput);
119 148
 
120 149
                         //TAN
121
-                    } else if (mode.equals("3")) {
122
-                        answer = trigMenu.calcTan(trigInput);
150
+                    } else if (trigMode.equals("3")) {
151
+                        trigAnswer = trigMenu.calcTan(trigInput);
123 152
 
124 153
                         //ARCSIN
125
-                    } else if (mode.equals("4")) {
126
-                        answer = trigMenu.calcArcsin(trigInput);
154
+                    } else if (trigMode.equals("4")) {
155
+                        trigAnswer = trigMenu.calcArcsin(trigInput);
127 156
 
128 157
                         //ARCCOS
129
-                    } else if (mode.equals("5")) {
130
-                        answer = trigMenu.calcArccos(trigInput);
158
+                    } else if (trigMode.equals("5")) {
159
+                        trigAnswer = trigMenu.calcArccos(trigInput);
131 160
 
132 161
                         //ARCTAN
133
-                    } else if (mode.equals("6")) {
134
-                        answer = trigMenu.calcArctan(trigInput);
162
+                    } else if (trigMode.equals("6")) {
163
+                        trigAnswer = trigMenu.calcArctan(trigInput);
135 164
 
136
-                    } else if (mode.equals("7")) {
165
+                    } else if (trigMode.equals("7")) {
137 166
                         break;
138 167
 
139 168
                     } else {
140 169
                         //Error message if input does not match options, loops back to the top so they can try again.
141
-                        answer = Double.NaN;
170
+                        trigAnswer = Double.NaN;
142 171
 
143 172
                     }
144 173
 
145
-                    String trigAnswer = Double.toString(answer);
146
-                    Console.println(trigAnswer);
174
+                    String trigAnswerString = Double.toString(trigAnswer);
175
+                    Console.println(trigAnswerString);
147 176
 
148 177
                     String trigDefRad =  Console.getStringInput("Do you want to convert your answer from radians to degrees?"
149 178
                             + "\nEnter Y or N").toLowerCase();
150 179
 
151 180
                     if (trigDefRad.equals("y") ) {
152
-                        trigMenu.toDegrees(answer);
181
+                        double convertAnswer = trigMenu.toDegrees(trigAnswer);
182
+                        Console.println(Double.toString(convertAnswer));
153 183
                     }
154 184
                     break;
155 185
                 } else {

+ 15
- 39
RealAdvanced.java 查看文件

@@ -11,61 +11,37 @@ import java.util.*;
11 11
 public class RealAdvanced
12 12
 {
13 13
 
14
-    public void RealAdvanced()
14
+    public void realAdvanced()
15 15
     {
16
-        String prompt1 = "Please Select one of the following Calculations: " +"\n"+
17
-            "Option 1: x^2" + "\n"+
18
-            "Option 2: x^y" + "\n"+
19
-            "Option 3: 1/x" + "\n"+
20
-            "Option 4: Switch Sign of x" + "\n"+
21
-            "Option 5: Return to Main Menu";
16
+        Console.println("Please Select one of the following Calculations: " +"\n"+
17
+            "1: x^2" + "\n"+
18
+            "2: x^y" + "\n"+
19
+            "3: 1/x" + "\n"+
20
+            "4: Switch Sign of x" + "\n"+
21
+            "5: Return to Main Menu");
22 22
 
23
-        Integer option = Console.getIntegerInput(prompt1);
24
-        String prompt = "Enter value of x";
25
-        double x = Console.getDoubleInput(prompt1);
26
-        while (option != 5){
27
-            if (option == 1){
28
-                squared(x);
29
-
30
-            }else if (option == 2){
31
-                String prompt2= "Enter Value of y";
32
-                double y = Console.getDoubleInput(prompt2);
33
-                exponent(x,y);
34
-
35
-            }else if (option == 3){
36
-                String prompt3= "Enter Value of x";
37
-                int input = Console.getIntegerInput(prompt3);
38
-                inverse(input);
39
-
40
-            }else if (option == 4){
41
-                opposite(x);
42
-
43
-            }else {
44
-                Console.println("Invalid input");
45
-            }
46
-        } 
47 23
     }
48 24
     // method to find x^2
49
-    public void squared(double x){
25
+    public double squared(double x){
50 26
 
51
-        Console.println(Double.toString(Math.pow(x,2)));
27
+        return Math.pow(x,2);
52 28
     }
53 29
     // method to find x^y
54
-    public void exponent(double x, double y){
30
+    public double exponent(double x, double y){
55 31
 
56
-        Console.println(Double.toString(Math.pow(x,y)));
32
+        return Math.pow(x,y);
57 33
     }
58 34
     // method to find the inverse of x
59
-    public void inverse(int x){
35
+    public double inverse(double x){
60 36
 
61
-        Console.println(Integer.toString(Integer.reverse(x)));
37
+        return 1/x;
62 38
     }
63 39
     // method to switch sign of x
64
-    public void opposite(double x){
40
+    public double opposite(double x){
65 41
 
66 42
         double opposite1 = -1 * x;
67
-        Console.println(Double.toString(opposite1));
68 43
 
44
+        return opposite1;
69 45
     }
70 46
 
71 47
 }

+ 1
- 6
SwitchDisplay.java 查看文件

@@ -30,19 +30,14 @@ public class SwitchDisplay
30 30
      * switchDisplayMode(String mode) sets the display to the mode given
31 31
      */
32 32
     
33
-    public String switchDisplay()
33
+    public void switchDisplay()
34 34
     {
35
-        String mode = "Invalid Input";
36
-        
37
-        while (mode.equals("Invalid Input")) {
38 35
             Console.println("Display Options" 
39 36
                              + "\n1: Binary"
40 37
                              + "\n2: Octal"
41 38
                              + "\n3: Decimal"
42 39
                              + "\n4: Hexadecimal"
43 40
                              + "\n5: Cancel - returns to Main Menu");
44
-        }
45
-        return mode = Console.getStringInput("Enter the desired display mode: ");
46 41
                          
47 42
     }
48 43
     

+ 105
- 24
package.bluej 查看文件

@@ -1,26 +1,65 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
2
+dependency1.from=MainMenu
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=RealAdvanced
5
+dependency10.from=Console
6
+dependency10.to=Basic
7
+dependency10.type=UsesDependency
8
+dependency11.from=Console
9
+dependency11.to=RealAdvanced
10
+dependency11.type=UsesDependency
11
+dependency12.from=Console
12
+dependency12.to=SciCalc
13
+dependency12.type=UsesDependency
14
+dependency13.from=Console
15
+dependency13.to=MemoryFunc
16
+dependency13.type=UsesDependency
17
+dependency14.from=Console
18
+dependency14.to=SwitchDisplay
19
+dependency14.type=UsesDependency
20
+dependency15.from=Console
21
+dependency15.to=Trig
22
+dependency15.type=UsesDependency
23
+dependency2.from=SciCalc
6 24
 dependency2.to=Console
7 25
 dependency2.type=UsesDependency
8
-editor.fx.0.height=709
9
-editor.fx.0.width=800
10
-editor.fx.0.x=338
11
-editor.fx.0.y=23
12
-objectbench.height=198
26
+dependency3.from=MainApplication
27
+dependency3.to=Console
28
+dependency3.type=UsesDependency
29
+dependency4.from=MemoryFunc
30
+dependency4.to=Console
31
+dependency4.type=UsesDependency
32
+dependency5.from=SwitchDisplay
33
+dependency5.to=Console
34
+dependency5.type=UsesDependency
35
+dependency6.from=Trig
36
+dependency6.to=Console
37
+dependency6.type=UsesDependency
38
+dependency7.from=Basic
39
+dependency7.to=Console
40
+dependency7.type=UsesDependency
41
+dependency8.from=RealAdvanced
42
+dependency8.to=Console
43
+dependency8.type=UsesDependency
44
+dependency9.from=Console
45
+dependency9.to=MainMenu
46
+dependency9.type=UsesDependency
47
+editor.fx.0.height=749
48
+editor.fx.0.width=1215
49
+editor.fx.0.x=145
50
+editor.fx.0.y=74
51
+objectbench.height=214
13 52
 objectbench.width=595
14 53
 package.divider.horizontal=0.6
15
-package.divider.vertical=0.685099846390169
16
-package.editor.height=439
54
+package.divider.vertical=0.6847360912981455
55
+package.editor.height=473
17 56
 package.editor.width=493
18 57
 package.editor.x=35
19
-package.editor.y=23
20
-package.frame.height=709
58
+package.editor.y=59
59
+package.frame.height=759
21 60
 package.frame.width=619
22
-package.numDependencies=2
23
-package.numTargets=3
61
+package.numDependencies=15
62
+package.numTargets=9
24 63
 package.showExtends=true
25 64
 package.showUses=true
26 65
 project.charset=UTF-8
@@ -30,23 +69,65 @@ readme.width=47
30 69
 readme.x=10
31 70
 readme.y=10
32 71
 target1.height=50
33
-target1.name=RealAdvanced
72
+target1.name=Basic
34 73
 target1.showInterface=false
35 74
 target1.type=ClassTarget
36
-target1.width=110
37
-target1.x=300
38
-target1.y=40
75
+target1.width=80
76
+target1.x=320
77
+target1.y=180
39 78
 target2.height=50
40
-target2.name=Console
79
+target2.name=SciCalc
41 80
 target2.showInterface=false
42 81
 target2.type=ClassTarget
43 82
 target2.width=80
44
-target2.x=80
45
-target2.y=200
83
+target2.x=10
84
+target2.y=280
46 85
 target3.height=50
47
-target3.name=MainApplication
86
+target3.name=RealAdvanced
48 87
 target3.showInterface=false
49 88
 target3.type=ClassTarget
50
-target3.width=120
51
-target3.x=70
52
-target3.y=70
89
+target3.width=110
90
+target3.x=170
91
+target3.y=10
92
+target4.height=50
93
+target4.name=MemoryFunc
94
+target4.showInterface=false
95
+target4.type=ClassTarget
96
+target4.width=110
97
+target4.x=210
98
+target4.y=350
99
+target5.height=50
100
+target5.name=Console
101
+target5.showInterface=false
102
+target5.type=ClassTarget
103
+target5.width=80
104
+target5.x=70
105
+target5.y=170
106
+target6.height=50
107
+target6.name=Trig
108
+target6.showInterface=false
109
+target6.type=ClassTarget
110
+target6.width=80
111
+target6.x=320
112
+target6.y=70
113
+target7.height=50
114
+target7.name=SwitchDisplay
115
+target7.showInterface=false
116
+target7.type=ClassTarget
117
+target7.width=110
118
+target7.x=80
119
+target7.y=350
120
+target8.height=50
121
+target8.name=MainMenu
122
+target8.showInterface=false
123
+target8.type=ClassTarget
124
+target8.width=90
125
+target8.x=70
126
+target8.y=10
127
+target9.height=50
128
+target9.name=MainApplication
129
+target9.showInterface=false
130
+target9.type=ClassTarget
131
+target9.width=120
132
+target9.x=70
133
+target9.y=70