Ver código fonte

merge conflict resolved

Michelle DiMarino 6 anos atrás
pai
commit
d558eeedba
8 arquivos alterados com 367 adições e 59 exclusões
  1. BIN
      .DS_Store
  2. 139
    0
      BasicTest.java
  3. 60
    20
      Console.java
  4. 1
    1
      MainMenu.java
  5. 7
    3
      MemoryFunc.java
  6. 1
    23
      SwitchDisplay.java
  7. 98
    0
      TrigTest.java
  8. 61
    12
      package.bluej

BIN
.DS_Store Ver arquivo


+ 139
- 0
BasicTest.java Ver arquivo

@@ -0,0 +1,139 @@
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 BasicTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class BasicTest
15
+{
16
+    /**
17
+     * Default constructor for test class BasicTest
18
+     */
19
+    public BasicTest()
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 testAdd()
45
+    {
46
+        Basic basic1 = new Basic();
47
+        assertEquals(14, basic1.getSum(4, 10), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void testAddDec()
52
+    {
53
+        Basic basic1 = new Basic();
54
+        assertEquals(13.27, basic1.getSum(13.2, 0.07), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void testAddNeg()
59
+    {
60
+        Basic basic1 = new Basic();
61
+        basic1.Basic();
62
+        assertEquals(6, basic1.getSum(-3, 9), 0.1);
63
+    }
64
+
65
+    @Test
66
+    public void testSub()
67
+    {
68
+        Basic basic1 = new Basic();
69
+        assertEquals(5, basic1.getDiff(10, 5), 0.1);
70
+    }
71
+
72
+    @Test
73
+    public void testSubDec()
74
+    {
75
+        Basic basic1 = new Basic();
76
+        assertEquals(4.65, basic1.getDiff(13.2, 8.55), 0.1);
77
+    }
78
+
79
+    @Test
80
+    public void testSubNeg()
81
+    {
82
+        Basic basic1 = new Basic();
83
+        assertEquals(18, basic1.getDiff(6, -12), 0.1);
84
+    }
85
+
86
+    @Test
87
+    public void testMul()
88
+    {
89
+        Basic basic1 = new Basic();
90
+        assertEquals(15, basic1.getProduct(3, 5), 0.1);
91
+    }
92
+
93
+    @Test
94
+    public void testMulDec()
95
+    {
96
+        Basic basic1 = new Basic();
97
+        assertEquals(6.8, basic1.getProduct(3.4, 2), 0.1);
98
+    }
99
+
100
+    @Test
101
+    public void testMulNeg()
102
+    {
103
+        Basic basic1 = new Basic();
104
+        assertEquals(10, basic1.getProduct(-2, -5), 0.1);
105
+    }
106
+
107
+    @Test
108
+    public void testDiv()
109
+    {
110
+        Basic basic1 = new Basic();
111
+        assertEquals(4, basic1.getQuotient(12, 3), 0.1);
112
+    }
113
+
114
+    @Test
115
+    public void testDivDec()
116
+    {
117
+        Basic basic1 = new Basic();
118
+        assertEquals(7.4, basic1.getQuotient(14.8, 2), 0.1);
119
+    }
120
+
121
+    @Test
122
+    public void testDivNeg()
123
+    {
124
+        Basic basic1 = new Basic();
125
+        assertEquals(-3, basic1.getQuotient(-12, 4), 0.1);
126
+    }
127
+}
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+

+ 60
- 20
Console.java Ver arquivo

@@ -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,11 +65,12 @@ 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) {
61 72
                         Console.println("undefined");
73
+                        basicAnswer = Double.NaN;
62 74
                         //Insert return to main menu.
63 75
                     } else {
64 76
                         basicAnswer = basicCalc.getQuotient(basicInput1, basicInput2);
@@ -72,9 +84,11 @@ public class Console {
72 84
                     basicAnswer = Double.NaN;
73 85
                     Console.println("Invalid Input");
74 86
                 }
87
+
75 88
                 Console.println(Double.toString(basicAnswer));
76 89
 
77 90
                 break;
91
+
78 92
                 case "2":
79 93
                 advCalc.realAdvanced();
80 94
                 String mode = Console.getStringInput("Enter the mode: ");
@@ -92,8 +106,12 @@ public class Console {
92 106
                     advAnswer = advCalc.exponent(advInput1,advInput2);
93 107
 
94 108
                 }else if (mode.equals("3")){
109
+                    if (advInput1 == 0) {
110
+                        Console.println("undefined");
111
+                        advAnswer = Double.NaN;
112
+                    } else {
95 113
                     advAnswer = advCalc.inverse(advInput1);
96
-
114
+                }
97 115
                 }else if (mode.equals("4")){
98 116
                     advAnswer = advCalc.opposite(advInput1);
99 117
                 }else if (mode.equals("5")){
@@ -119,16 +137,36 @@ public class Console {
119 137
                 // if statement to use various calc functions
120 138
                 if (sciMenuInput.equals("1")) {
121 139
                     // Base Conversions
122
-                    // while loop for display 
140
+                    // while loop for display
123 141
                     String baseMode = "";
124 142
 
125
-                    baseChange.switchDisplay(); 
143
+                    baseChange.switchDisplay();
144
+                    String baseAnswer = "";
126 145
                     baseMode = Console.getStringInput("Enter the desired display mode: ");
127
-
128 146
                     int userInput = getIntegerInput("Enter the number you want to convert to selected base: ");
129 147
 
130
-                    String baseOutput = baseChange.switchDisplayOutput(baseMode, userInput);
131
-                    Console.println(baseOutput);
148
+                    switch (baseMode) {
149
+                        case "1":
150
+                        baseAnswer = baseChange.toBinary(userInput);
151
+
152
+                        case "2":
153
+                        baseAnswer = baseChange.toOctal(userInput);
154
+
155
+                        case "3":
156
+                        baseAnswer = baseChange.toDecimal(userInput);
157
+
158
+                        case "4":
159
+                        baseAnswer = baseChange.toHexa(userInput);
160
+
161
+                        case "5":
162
+                        break;
163
+
164
+                        default:
165
+                        Console.println("Invalid Input");
166
+                        break;
167
+                    }
168
+
169
+                    Console.println(baseAnswer);
132 170
 
133 171
                     break;
134 172
                     // display mode
@@ -136,7 +174,9 @@ public class Console {
136 174
                     // asks for input
137 175
                 } else if (sciMenuInput.equals("2")) {
138 176
                     // Memory
177
+                    // access memory menu
139 178
                     memory.memoryMenu();
179
+
140 180
                 } else if (sciMenuInput.equals("3")) {
141 181
                     // To Trig Menu
142 182
                     trigMenu.trigFunctions();

+ 1
- 1
MainMenu.java Ver arquivo

@@ -22,7 +22,7 @@ public class MainMenu
22 22
     
23 23
     public void mainMenuDisplay()
24 24
     {
25
-        Console.println("Calculator Options:"
25
+        Console.println("\nCalculator Options:"
26 26
                          + "\n1: Basic Calculator (+ - * /)"
27 27
                          + "\n2: Advanced Calculator (Exponential Functions)"
28 28
                          + "\n3: Scientific Functions (Base Conversion, Memory, Trigonometry)"

+ 7
- 3
MemoryFunc.java Ver arquivo

@@ -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")) {

+ 1
- 23
SwitchDisplay.java Ver arquivo

@@ -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
      */

+ 98
- 0
TrigTest.java Ver arquivo

@@ -0,0 +1,98 @@
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 TrigTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class TrigTest
15
+{
16
+    /**
17
+     * Default constructor for test class TrigTest
18
+     */
19
+    public TrigTest()
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 testSIN()
45
+    {
46
+        Trig trig1 = new Trig();
47
+        assertEquals(-0.54402111088, trig1.calcSin(10), 0.1);
48
+    }
49
+
50
+    @Test
51
+    public void testCOS()
52
+    {
53
+        Trig trig1 = new Trig();
54
+        assertEquals(-0.83907152907, trig1.calcCos(10), 0.1);
55
+    }
56
+
57
+    @Test
58
+    public void testTAN()
59
+    {
60
+        Trig trig1 = new Trig();
61
+        assertEquals(0.64836082745, trig1.calcTan(10), 0.1);
62
+    }
63
+
64
+    @Test
65
+    public void testRadtoDeg()
66
+    {
67
+        Trig trig1 = new Trig();
68
+        assertEquals(37.14833901458697, trig1.toDegrees(0.64836082745), 0.1);
69
+    }
70
+
71
+    @Test
72
+    public void testArcSin()
73
+    {
74
+        Trig trig2 = new Trig();
75
+        assertEquals(0.523598776, trig2.calcArcsin(0.5), 0.1);
76
+    }
77
+
78
+    @Test
79
+    public void testArcTan()
80
+    {
81
+        Trig trig1 = new Trig();
82
+        assertEquals(0.463647609, trig1.calcArctan(0.5), 0.1);
83
+    }
84
+
85
+    @Test
86
+    public void testArcCos()
87
+    {
88
+        Trig trig1 = new Trig();
89
+        assertEquals(1.04719755, trig1.calcArccos(0.5), 0.1);
90
+    }
91
+}
92
+
93
+
94
+
95
+
96
+
97
+
98
+

+ 61
- 12
package.bluej Ver arquivo

@@ -27,21 +27,22 @@ dependency2.from=SciCalc
27 27
 dependency2.to=Console
28 28
 dependency2.type=UsesDependency
29 29
 dependency3.from=MemoryFunc
30
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
30 31
 dependency3.to=Console
31 32
 dependency3.type=UsesDependency
32 33
 dependency4.from=Trig
33 34
 dependency4.to=Console
34 35
 dependency4.type=UsesDependency
35
-dependency5.from=SwitchDisplay
36
+dependency5.from=Trig
36 37
 dependency5.to=Console
37 38
 dependency5.type=UsesDependency
38
-dependency6.from=MainMenu
39
+dependency6.from=SwitchDisplay
39 40
 dependency6.to=Console
40 41
 dependency6.type=UsesDependency
41
-dependency7.from=MainApplication
42
+dependency7.from=MainMenu
42 43
 dependency7.to=Console
43 44
 dependency7.type=UsesDependency
44
-dependency8.from=RealAdvanced
45
+dependency8.from=MainApplication
45 46
 dependency8.to=Console
46 47
 dependency8.type=UsesDependency
47 48
 dependency9.from=Console
@@ -61,8 +62,13 @@ package.editor.x=35
61 62
 package.editor.y=23
62 63
 package.frame.height=709
63 64
 package.frame.width=619
65
+<<<<<<< HEAD
66
+package.numDependencies=17
67
+package.numTargets=11
68
+=======
64 69
 package.numDependencies=16
65 70
 package.numTargets=10
71
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
66 72
 package.showExtends=true
67 73
 package.showUses=true
68 74
 project.charset=UTF-8
@@ -71,6 +77,7 @@ readme.name=@README
71 77
 readme.width=47
72 78
 readme.x=10
73 79
 readme.y=10
80
+target1.association=BasicTest
74 81
 target1.height=50
75 82
 target1.name=Basic
76 83
 target1.showInterface=false
@@ -79,12 +86,28 @@ target1.width=80
79 86
 target1.x=320
80 87
 target1.y=180
81 88
 target10.height=50
89
+<<<<<<< HEAD
90
+target10.name=MainMenu
91
+target10.showInterface=false
92
+target10.type=ClassTarget
93
+target10.width=90
94
+target10.x=70
95
+target10.y=10
96
+target11.height=50
97
+target11.name=MainApplication
98
+target11.showInterface=false
99
+target11.type=ClassTarget
100
+target11.width=120
101
+target11.x=70
102
+target11.y=70
103
+=======
82 104
 target10.name=MainApplication
83 105
 target10.showInterface=false
84 106
 target10.type=ClassTarget
85 107
 target10.width=120
86 108
 target10.x=70
87 109
 target10.y=70
110
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
88 111
 target2.height=50
89 112
 target2.name=SciCalc
90 113
 target2.showInterface=false
@@ -101,12 +124,21 @@ target3.width=110
101 124
 target3.x=170
102 125
 target3.y=10
103 126
 target4.height=50
127
+<<<<<<< HEAD
128
+target4.name=TrigTest
129
+target4.showInterface=false
130
+target4.type=UnitTestTargetJunit4
131
+target4.width=80
132
+target4.x=350
133
+target4.y=40
134
+=======
104 135
 target4.name=Console
105 136
 target4.showInterface=false
106 137
 target4.type=ClassTarget
107 138
 target4.width=80
108 139
 target4.x=70
109 140
 target4.y=170
141
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c
110 142
 target5.height=50
111 143
 target5.name=MemoryFunc
112 144
 target5.showInterface=false
@@ -115,20 +147,36 @@ target5.width=110
115 147
 target5.x=210
116 148
 target5.y=350
117 149
 target6.height=50
118
-target6.name=Trig
150
+target6.name=Console
119 151
 target6.showInterface=false
120 152
 target6.type=ClassTarget
121 153
 target6.width=80
122
-target6.x=320
123
-target6.y=70
154
+target6.x=70
155
+target6.y=170
124 156
 target7.height=50
125
-target7.name=SwitchDisplay
157
+target7.name=BasicTest
126 158
 target7.showInterface=false
127
-target7.type=ClassTarget
128
-target7.width=110
129
-target7.x=80
130
-target7.y=350
159
+target7.type=UnitTestTargetJunit4
160
+target7.width=80
161
+target7.x=350
162
+target7.y=150
163
+target8.association=TrigTest
131 164
 target8.height=50
165
+<<<<<<< HEAD
166
+target8.name=Trig
167
+target8.showInterface=false
168
+target8.type=ClassTarget
169
+target8.width=80
170
+target8.x=320
171
+target8.y=70
172
+target9.height=50
173
+target9.name=SwitchDisplay
174
+target9.showInterface=false
175
+target9.type=ClassTarget
176
+target9.width=110
177
+target9.x=80
178
+target9.y=350
179
+=======
132 180
 target8.name=RealAdvancedTest
133 181
 target8.showInterface=false
134 182
 target8.type=UnitTestTargetJunit4
@@ -142,3 +190,4 @@ target9.type=ClassTarget
142 190
 target9.width=90
143 191
 target9.x=70
144 192
 target9.y=10
193
+>>>>>>> 49d5555735b5e26b8076429d9dd1666b4918738c