Lauren Green пре 6 година
родитељ
комит
bd40934a5e
6 измењених фајлова са 226 додато и 69 уклоњено
  1. 57
    20
      Console.java
  2. 7
    3
      MemoryFunc.java
  3. 5
    6
      RealAdvanced.java
  4. 82
    0
      RealAdvancedTest.java
  5. 1
    23
      SwitchDisplay.java
  6. 74
    17
      package.bluej

+ 57
- 20
Console.java Прегледај датотеку

@@ -16,15 +16,6 @@ public class Console {
16 16
         SwitchDisplay baseChange = new SwitchDisplay();
17 17
         Trig trigMenu = new Trig();
18 18
 
19
-        // Stored memory value should be able to be used throughout whole application
20
-        Double memoryValue = memory.memory;
21
-
22
-        // blanket input statement 
23
-        // create input methods to call when we need them with specific types
24
-        // we use 1 input variable statement to call the user to input, then manipulate
25
-        // Can user input M if native type is double
26
-        // if any input = "m", that input now = memoryValue;
27
-
28 19
         // Menu Input
29 20
         String menuInput = " ";
30 21
         // Giant while loop that links back to main menu
@@ -37,16 +28,36 @@ public class Console {
37 28
                 case "1":
38 29
                 basicCalc.Basic();
39 30
 
31
+                double basicInput1 = 0,
32
+                basicInput2 = 0;
33
+
40 34
                 String basicMode = Console.getStringInput("Enter the mode: ");
41
-                double basicInput1 = Console.getDoubleInput("Enter the first input: ");
42
-                double basicInput2 = Console.getDoubleInput("Enter the second input: ");
43 35
 
44
-                double basicAnswer = 0;
36
+                if (memory.memoryChanged != true) {
37
+                    basicInput1 = Console.getDoubleInput("Enter the first input: ");
38
+                    basicInput2 = Console.getDoubleInput("Enter the second input: ");
39
+                } else if (memory.memoryChanged == true) {
40
+                    String useMemory = Console.getStringInput("Do you want to use the stored memory value? Y or N: ").toLowerCase();
41
+                    if (useMemory.equals("y")) {
42
+                        String whichBasInput = Console.getStringInput("Which input? 1 or 2 or both").toLowerCase();
43
+                        if (whichBasInput.equals("1")) {
44
+                            basicInput1 = memory.memory;
45
+                            basicInput2 = Console.getDoubleInput("Enter the second input: ");
46
+                        } else if (whichBasInput.equals("2")) {
47
+                            basicInput2 = memory.memory;
48
+                            basicInput1 = Console.getDoubleInput("Enter the first input: ");
49
+                        } else if (whichBasInput.equals("both")) {
50
+                            basicInput1 = memory.memory;
51
+                            basicInput2 = memory.memory;
52
+                        }
53
+                    }
54
+                }
45 55
 
56
+                double basicAnswer = 0;
46 57
                 if (basicMode.equals("1")) {
47 58
                     basicAnswer = basicCalc.getSum(basicInput1, basicInput2);
48 59
 
49
-                    //subtraction    
60
+                    //subtraction
50 61
                 } else if (basicMode.equals("2")) {
51 62
                     basicAnswer = basicCalc.getDiff(basicInput1, basicInput2);
52 63
 
@@ -54,7 +65,7 @@ public class Console {
54 65
                 } else if (basicMode.equals("3")) {
55 66
                     basicAnswer = basicCalc.getProduct(basicInput1, basicInput2);
56 67
 
57
-                    //division    
68
+                    //division
58 69
                 } else if (basicMode.equals("4")) {
59 70
                     //error message when trying to divide by 0.
60 71
                     if (basicInput2 == 0) {
@@ -103,8 +114,12 @@ public class Console {
103 114
                 }
104 115
                 }else if (mode.equals("4")){
105 116
                     advAnswer = advCalc.opposite(advInput1);
117
+                }else if (mode.equals("5")){
118
+                    advAnswer = advCalc.absoluteValue(advInput1);
106 119
 
107
-                }else {
120
+                }else if (mode.equals("6")) {
121
+                    break;
122
+                }else{
108 123
                     Console.println("Invalid input");
109 124
                 }
110 125
 
@@ -120,16 +135,36 @@ public class Console {
120 135
                 // if statement to use various calc functions
121 136
                 if (sciMenuInput.equals("1")) {
122 137
                     // Base Conversions
123
-                    // while loop for display 
138
+                    // while loop for display
124 139
                     String baseMode = "";
125 140
 
126
-                    baseChange.switchDisplay(); 
141
+                    baseChange.switchDisplay();
142
+                    String baseAnswer = "";
127 143
                     baseMode = Console.getStringInput("Enter the desired display mode: ");
128
-
129 144
                     int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
130 145
 
131
-                    String baseOutput = baseChange.switchDisplayOutput(baseMode, userInput);
132
-                    Console.println(baseOutput);
146
+                    switch (baseMode) {
147
+                        case "1":
148
+                        baseAnswer = baseChange.toBinary(userInput);
149
+
150
+                        case "2":
151
+                        baseAnswer = baseChange.toOctal(userInput);
152
+
153
+                        case "3":
154
+                        baseAnswer = baseChange.toDecimal(userInput);
155
+
156
+                        case "4":
157
+                        baseAnswer = baseChange.toHexa(userInput);
158
+
159
+                        case "5":
160
+                        break;
161
+
162
+                        default:
163
+                        Console.println("Invalid Input");
164
+                        break;
165
+                    }
166
+
167
+                    Console.println(baseAnswer);
133 168
 
134 169
                     break;
135 170
                     // display mode
@@ -137,7 +172,9 @@ public class Console {
137 172
                     // asks for input
138 173
                 } else if (sciMenuInput.equals("2")) {
139 174
                     // Memory
175
+                    // access memory menu
140 176
                     memory.memoryMenu();
177
+
141 178
                 } else if (sciMenuInput.equals("3")) {
142 179
                     // To Trig Menu
143 180
                     trigMenu.trigFunctions();

+ 7
- 3
MemoryFunc.java Прегледај датотеку

@@ -4,11 +4,14 @@
4 4
  */
5 5
 public class MemoryFunc {
6 6
     public Double memory;
7
+    public Boolean memoryChanged;
7 8
     public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
8 9
 
9 10
     public MemoryFunc() {
10 11
         this.memory = DEFAULT_MEMORY_VALUE;
12
+        this.memoryChanged = false;
11 13
     }
14
+    
12 15
     /**
13 16
      * Menu
14 17
      * Clear
@@ -20,20 +23,21 @@ public class MemoryFunc {
20 23
         
21 24
         Console.println("Memory Menu"
22 25
                          + "\n1: M+ - Update stored memory value"
23
-                         + "\n2: nMC - Clear to default memory value"
24
-                         + "\n3: nMCR - Display stored memory value"
26
+                         + "\n2: MC - Clear to default memory value"
27
+                         + "\n3: MCR - Display stored memory value"
25 28
                          + "\n4: Cancel - Returns to Main Menu");
26 29
                          
27 30
         String memoryOpt = "";
28 31
         
29 32
         while (!memoryOpt.equals("4")) {
30 33
             
31
-            memoryOpt = Console.getStringInput("Select option by typing the key. (ie 1 for M+)");
34
+            memoryOpt = Console.getStringInput("Select option by typing the key. (ie. 1 for M+)");
32 35
             
33 36
             if (memoryOpt.equals("1")) {
34 37
                 
35 38
                 Double newMemory = Console.getDoubleInput("Enter the value to store");
36 39
                 this.memory = updateMemory(newMemory);
40
+                this.memoryChanged = true;
37 41
                 break;
38 42
                 
39 43
             } else if (memoryOpt.equals("2")) {

+ 5
- 6
RealAdvanced.java Прегледај датотеку

@@ -18,30 +18,29 @@ public class RealAdvanced
18 18
             "2: x^y" + "\n"+
19 19
             "3: 1/x" + "\n"+
20 20
             "4: Switch Sign of x" + "\n"+
21
-            "5: Return to Main Menu");
21
+            "5: Absolute Value of x" + "\n"+
22
+            "6: Return to Main Menu");
22 23
 
23 24
     }
24 25
     // method to find x^2
25 26
     public double squared(double x){
26
-
27 27
         return Math.pow(x,2);
28 28
     }
29 29
     // method to find x^y
30 30
     public double exponent(double x, double y){
31
-
32 31
         return Math.pow(x,y);
33 32
     }
34 33
     // method to find the inverse of x
35 34
     public double inverse(double x){
36
-
37 35
         return 1/x;
38 36
     }
39 37
     // method to switch sign of x
40 38
     public double opposite(double x){
41
-
42 39
         double opposite1 = -1 * x;
43
-
44 40
         return opposite1;
45 41
     }
42
+    public double absoluteValue(double x){
43
+        return Math.abs(x);
44
+    }
46 45
 
47 46
 }

+ 82
- 0
RealAdvancedTest.java Прегледај датотеку

@@ -0,0 +1,82 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class RealAdvancedTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class RealAdvancedTest
15
+{
16
+    /**
17
+     * Default constructor for test class RealAdvancedTest
18
+     */
19
+    public RealAdvancedTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+    @Test
44
+    public void squaredTest()
45
+    {
46
+        RealAdvanced realAdva1 = new RealAdvanced();
47
+        assertEquals(9.0, realAdva1.squared(3), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void exponentTest()
52
+    {
53
+        RealAdvanced realAdva1 = new RealAdvanced();
54
+        assertEquals(8.0, realAdva1.exponent(2, 3), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void oppositeTest()
59
+    {
60
+        RealAdvanced realAdva1 = new RealAdvanced();
61
+        assertEquals(2.0, realAdva1.opposite(-2), 0.1);
62
+    }
63
+
64
+    @Test
65
+    public void inverseTest()
66
+    {
67
+        RealAdvanced realAdva1 = new RealAdvanced();
68
+        assertEquals(0.5, realAdva1.inverse(2), 0.1);
69
+    }
70
+
71
+    @Test
72
+    public void absoluteTest()
73
+    {
74
+        RealAdvanced realAdva1 = new RealAdvanced();
75
+        assertEquals(4.0, realAdva1.absoluteValue(-4), 0.1);
76
+    }
77
+}
78
+
79
+
80
+
81
+
82
+

+ 1
- 23
SwitchDisplay.java Прегледај датотеку

@@ -40,29 +40,7 @@ public class SwitchDisplay
40 40
                              + "\n5: Cancel - returns to Main Menu");
41 41
                          
42 42
     }
43
-    
44
-    public String switchDisplayOutput(String mode, int baseInput) {
45
-        switch (mode) {
46
-            case "1":
47
-                return toBinary(baseInput);
48
-                
49
-            case "2":
50
-                return toOctal(baseInput);
51
-                
52
-            case "3":
53
-                return toDecimal(baseInput);
54
-                
55
-            case "4":
56
-                return toHexa(baseInput);
57
-                
58
-            case "5":
59
-                return mode;
60
-                
61
-            default:
62
-                return "Invalid Input";
63
-        }
64
-    }
65
-    
43
+
66 44
     /**
67 45
      * Converts the user input into corresponding base types
68 46
      */

+ 74
- 17
package.bluej Прегледај датотеку

@@ -3,23 +3,24 @@ dependency1.from=Basic
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5 5
 dependency10.from=Console
6
-dependency10.to=Basic
6
+dependency10.to=MainMenu
7 7
 dependency10.type=UsesDependency
8 8
 dependency11.from=Console
9
-dependency11.to=RealAdvanced
9
+dependency11.to=Basic
10 10
 dependency11.type=UsesDependency
11 11
 dependency12.from=Console
12
-dependency12.to=SciCalc
12
+dependency12.to=RealAdvanced
13 13
 dependency12.type=UsesDependency
14 14
 dependency13.from=Console
15
-dependency13.to=MemoryFunc
15
+dependency13.to=SciCalc
16 16
 dependency13.type=UsesDependency
17 17
 dependency14.from=Console
18
-dependency14.to=SwitchDisplay
18
+dependency14.to=MemoryFunc
19 19
 dependency14.type=UsesDependency
20 20
 dependency15.from=Console
21
-dependency15.to=Trig
21
+dependency15.to=SwitchDisplay
22 22
 dependency15.type=UsesDependency
23
+<<<<<<< HEAD
23 24
 dependency16.from=BasicTest
24 25
 dependency16.to=Basic
25 26
 dependency16.type=UsesDependency
@@ -30,42 +31,63 @@ dependency2.from=SciCalc
30 31
 dependency2.to=Console
31 32
 dependency2.type=UsesDependency
32 33
 dependency3.from=RealAdvanced
34
+=======
35
+dependency16.from=Console
36
+dependency16.to=Trig
37
+dependency16.type=UsesDependency
38
+dependency2.from=SciCalc
39
+dependency2.to=Console
40
+dependency2.type=UsesDependency
41
+dependency3.from=MemoryFunc
42
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
33 43
 dependency3.to=Console
34 44
 dependency3.type=UsesDependency
35
-dependency4.from=MemoryFunc
45
+dependency4.from=Trig
36 46
 dependency4.to=Console
37 47
 dependency4.type=UsesDependency
38 48
 dependency5.from=Trig
39 49
 dependency5.to=Console
40 50
 dependency5.type=UsesDependency
51
+<<<<<<< HEAD
41 52
 dependency6.from=SwitchDisplay
42 53
 dependency6.to=Console
43 54
 dependency6.type=UsesDependency
44 55
 dependency7.from=MainMenu
56
+=======
57
+dependency6.from=MainMenu
58
+dependency6.to=Console
59
+dependency6.type=UsesDependency
60
+dependency7.from=MainApplication
61
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
45 62
 dependency7.to=Console
46 63
 dependency7.type=UsesDependency
47 64
 dependency8.from=MainApplication
48 65
 dependency8.to=Console
49 66
 dependency8.type=UsesDependency
50
-dependency9.from=Console
51
-dependency9.to=MainMenu
67
+dependency9.from=RealAdvancedTest
68
+dependency9.to=RealAdvanced
52 69
 dependency9.type=UsesDependency
53
-editor.fx.0.height=749
70
+editor.fx.0.height=709
54 71
 editor.fx.0.width=1215
55
-editor.fx.0.x=145
56
-editor.fx.0.y=74
57
-objectbench.height=214
72
+editor.fx.0.x=65
73
+editor.fx.0.y=23
74
+objectbench.height=198
58 75
 objectbench.width=595
59 76
 package.divider.horizontal=0.6
60
-package.divider.vertical=0.6847360912981455
61
-package.editor.height=473
77
+package.divider.vertical=0.685099846390169
78
+package.editor.height=439
62 79
 package.editor.width=493
63 80
 package.editor.x=35
64
-package.editor.y=59
65
-package.frame.height=759
81
+package.editor.y=23
82
+package.frame.height=709
66 83
 package.frame.width=619
84
+<<<<<<< HEAD
67 85
 package.numDependencies=17
68 86
 package.numTargets=11
87
+=======
88
+package.numDependencies=16
89
+package.numTargets=10
90
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
69 91
 package.showExtends=true
70 92
 package.showUses=true
71 93
 project.charset=UTF-8
@@ -83,6 +105,7 @@ target1.width=80
83 105
 target1.x=320
84 106
 target1.y=180
85 107
 target10.height=50
108
+<<<<<<< HEAD
86 109
 target10.name=MainMenu
87 110
 target10.showInterface=false
88 111
 target10.type=ClassTarget
@@ -96,6 +119,14 @@ target11.type=ClassTarget
96 119
 target11.width=120
97 120
 target11.x=70
98 121
 target11.y=70
122
+=======
123
+target10.name=MainApplication
124
+target10.showInterface=false
125
+target10.type=ClassTarget
126
+target10.width=120
127
+target10.x=70
128
+target10.y=70
129
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
99 130
 target2.height=50
100 131
 target2.name=SciCalc
101 132
 target2.showInterface=false
@@ -103,6 +134,7 @@ target2.type=ClassTarget
103 134
 target2.width=80
104 135
 target2.x=10
105 136
 target2.y=280
137
+target3.association=RealAdvancedTest
106 138
 target3.height=50
107 139
 target3.name=RealAdvanced
108 140
 target3.showInterface=false
@@ -111,12 +143,21 @@ target3.width=110
111 143
 target3.x=170
112 144
 target3.y=10
113 145
 target4.height=50
146
+<<<<<<< HEAD
114 147
 target4.name=TrigTest
115 148
 target4.showInterface=false
116 149
 target4.type=UnitTestTargetJunit4
117 150
 target4.width=80
118 151
 target4.x=350
119 152
 target4.y=40
153
+=======
154
+target4.name=Console
155
+target4.showInterface=false
156
+target4.type=ClassTarget
157
+target4.width=80
158
+target4.x=70
159
+target4.y=170
160
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
120 161
 target5.height=50
121 162
 target5.name=MemoryFunc
122 163
 target5.showInterface=false
@@ -140,6 +181,7 @@ target7.x=350
140 181
 target7.y=150
141 182
 target8.association=TrigTest
142 183
 target8.height=50
184
+<<<<<<< HEAD
143 185
 target8.name=Trig
144 186
 target8.showInterface=false
145 187
 target8.type=ClassTarget
@@ -153,3 +195,18 @@ target9.type=ClassTarget
153 195
 target9.width=110
154 196
 target9.x=80
155 197
 target9.y=350
198
+=======
199
+target8.name=RealAdvancedTest
200
+target8.showInterface=false
201
+target8.type=UnitTestTargetJunit4
202
+target8.width=110
203
+target8.x=200
204
+target8.y=-20
205
+target9.height=50
206
+target9.name=MainMenu
207
+target9.showInterface=false
208
+target9.type=ClassTarget
209
+target9.width=90
210
+target9.x=70
211
+target9.y=10
212
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c