Browse Source

troubleshot display mode methods, all working now

Margaret Pierse 6 years ago
parent
commit
a07a337575
2 changed files with 25 additions and 16 deletions
  1. 16
    16
      MathMethods.java
  2. 9
    0
      MathMethodsTest.java

+ 16
- 16
MathMethods.java View File

@@ -9,7 +9,8 @@ import java.lang.*;
9 9
 public class MathMethods
10 10
 
11 11
 {
12
-
12
+    private static int displayModeCounter=4;
13
+    
13 14
     public static Double add(double n1, double n2){
14 15
         return (n1 + n2);
15 16
     }
@@ -83,15 +84,15 @@ public class MathMethods
83 84
 
84 85
     public static String switchDisplayMode(String mode){
85 86
         Calculator display = new Calculator();
86
-        
87
+
87 88
         String answer = "";
88 89
         switch (mode) {
89 90
             case "binary":
90
-            answer = "0b" + Integer.toBinaryString((int)display.memory);
91
+            answer = "0b " + Integer.toBinaryString((int)display.memory);
91 92
             break;
92 93
 
93 94
             case "octal":
94
-            answer = "octal" + Integer.toOctalString((int)display.memory);
95
+            answer = "0 " + Integer.toOctalString((int)display.memory);
95 96
             break;
96 97
 
97 98
             case "decimal":
@@ -99,31 +100,31 @@ public class MathMethods
99 100
             break;
100 101
 
101 102
             case "hexadecimal":
102
-            answer = Double.toHexString(display.memory);
103
+            answer = "0x " + Integer.toHexString((int)display.memory);
103 104
             break;
104 105
 
105 106
         }
106 107
         return answer;
107 108
     }
108 109
 
109
-    public static String switchDisplayMode(){
110
-        int i = 4;
110
+    public String switchDisplayMode(){
111
+
111 112
         String answer = "";
112 113
 
113
-        if (i%4 == 0){ 
114
+        if (displayModeCounter%4 == 0){ 
114 115
             answer = switchDisplayMode("binary");
115
-            i++;
116
+            displayModeCounter++;
116 117
         } 
117
-        else if (i%4 == 1){
118
+        else if (displayModeCounter%4 == 1){
118 119
             answer = switchDisplayMode("octal");
119
-            i++;
120
+            displayModeCounter++;
120 121
         } 
121
-        else if (i%4 == 2) {
122
-            answer = switchDisplayMode("hecadecimal");
123
-            i++;
122
+        else if (displayModeCounter%4 == 2) {
123
+            answer = switchDisplayMode("hexadecimal");
124
+            displayModeCounter++;
124 125
         } else {
125 126
             answer = switchDisplayMode("decimal");
126
-            i++;
127
+            displayModeCounter++;
127 128
         }
128 129
         return answer;
129 130
     }
@@ -135,4 +136,3 @@ public class MathMethods
135 136
 
136 137
 }
137 138
 
138
-

+ 9
- 0
MathMethodsTest.java View File

@@ -77,6 +77,14 @@ public class MathMethodsTest
77 77
     }
78 78
 
79 79
     
80
+
81
+    // @Test
82
+    // public void testOctalDisplay()
83
+    // {
84
+        // MathMethods mathMethods1 = new MathMethods();
85
+        // mathMethods1.memory = 20;
86
+        // assertEquals(0 24, MathMethods.switchDisplayMode("octal"));
87
+    // }
80 88
 }
81 89
 
82 90
 
@@ -85,3 +93,4 @@ public class MathMethodsTest
85 93
 
86 94
 
87 95
 
96
+