Procházet zdrojové kódy

added the rest of the display mode methods

Margaret Pierse před 6 roky
rodič
revize
8573e1553e
3 změnil soubory, kde provedl 50 přidání a 42 odebrání
  1. 8
    3
      Calculator.java
  2. 26
    26
      MathMethods.java
  3. 16
    13
      package.bluej

+ 8
- 3
Calculator.java Zobrazit soubor

@@ -137,19 +137,24 @@ public static double memory = 0;
137 137
                     break;
138 138
 
139 139
                     case "display mode decimal":
140
-                    calc.printAns(String.valueOf(calc.switchDisplayMode("decimal")));
140
+                    calc.printAns(String.valueOf(memory));
141 141
                     break;
142 142
                     
143 143
                     case "display mode hexadecimal":
144 144
                     calc.printAns(calc.switchDisplayMode("hexadecimal"));
145 145
                     
146 146
                     case "display mode octal":
147
-                    calc.printAns(String.valueOf(calc.switchDisplayMode("octal")));
147
+                    calc.printAns(calc.switchDisplayMode("octal"));
148 148
                     break;
149 149
                     
150 150
                     case "display mode binary":
151
-                    calc.printAns(String.valueOf(calc.switchDisplayMode("binary")));
151
+                    calc.printAns(calc.switchDisplayMode("binary"));
152 152
                     break;
153
+                    
154
+                    case "display mode" :
155
+                    calc.printAns(calc.switchDisplayMode());
156
+                    break;
157
+                    
153 158
 
154 159
                 }
155 160
             }

+ 26
- 26
MathMethods.java Zobrazit soubor

@@ -83,19 +83,19 @@ public class MathMethods
83 83
 
84 84
     public static String switchDisplayMode(String mode){
85 85
         Calculator display = new Calculator();
86
-        //Double d = new Double(display.memory);
86
+        
87 87
         String answer = "";
88 88
         switch (mode) {
89 89
             case "binary":
90
-            answer = "";
90
+            answer = "0b" + Integer.toBinaryString((int)display.memory);
91 91
             break;
92 92
 
93 93
             case "octal":
94
-            answer = "";
94
+            answer = "octal" + Integer.toOctalString((int)display.memory);
95 95
             break;
96 96
 
97 97
             case "decimal":
98
-            answer = "";
98
+            answer = String.valueOf(display.memory);
99 99
             break;
100 100
 
101 101
             case "hexadecimal":
@@ -106,30 +106,30 @@ public class MathMethods
106 106
         return answer;
107 107
     }
108 108
 
109
-    // public static double switchDisplayMode(){
110
-        // int i = 4;
111
-        // double answer = 0;
112
-
113
-        // if (i%4 == 0){ 
114
-            // answer = switchDisplayMode("binary");
115
-            // i++;
116
-        // } 
117
-        // else if (i%4 == 1){
118
-            // answer = switchDisplayMode("octal");
119
-            // i++;
120
-        // } 
121
-        // else if (i%4 == 2) {
122
-            // answer = switchDisplayMode("hecadecimal");
123
-            // i++;
124
-        // } else {
125
-            // answer = switchDisplayMode("decimal");
126
-            // i++;
127
-        // }
128
-        // return answer;
129
-    // }
109
+    public static String switchDisplayMode(){
110
+        int i = 4;
111
+        String answer = "";
112
+
113
+        if (i%4 == 0){ 
114
+            answer = switchDisplayMode("binary");
115
+            i++;
116
+        } 
117
+        else if (i%4 == 1){
118
+            answer = switchDisplayMode("octal");
119
+            i++;
120
+        } 
121
+        else if (i%4 == 2) {
122
+            answer = switchDisplayMode("hecadecimal");
123
+            i++;
124
+        } else {
125
+            answer = switchDisplayMode("decimal");
126
+            i++;
127
+        }
128
+        return answer;
129
+    }
130 130
 
131 131
     public static void printAns(String printAnswer){
132
-        System.out.println("ANSWER: " + printAnswer);
132
+        System.out.println("ANSWER: " + printAnswer + "\n \n");
133 133
 
134 134
     }
135 135
 

+ 16
- 13
package.bluej Zobrazit soubor

@@ -1,25 +1,28 @@
1 1
 #BlueJ package file
2
-dependency1.from=Calculator
2
+dependency1.from=MathMethodsTest
3 3
 dependency1.to=MathMethods
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=MathMethodsTest
5
+dependency2.from=Calculator
6 6
 dependency2.to=MathMethods
7 7
 dependency2.type=UsesDependency
8
-editor.fx.0.height=722
9
-editor.fx.0.width=800
10
-editor.fx.0.x=615
11
-editor.fx.0.y=114
8
+dependency3.from=MathMethods
9
+dependency3.to=Calculator
10
+dependency3.type=UsesDependency
11
+editor.fx.0.height=813
12
+editor.fx.0.width=1078
13
+editor.fx.0.x=294
14
+editor.fx.0.y=23
12 15
 objectbench.height=80
13 16
 objectbench.width=480
14 17
 package.divider.horizontal=0.5997536945812808
15 18
 package.divider.vertical=0.8838451268357811
16 19
 package.editor.height=655
17 20
 package.editor.width=706
18
-package.editor.x=100
19
-package.editor.y=26
21
+package.editor.x=356
22
+package.editor.y=23
20 23
 package.frame.height=807
21 24
 package.frame.width=832
22
-package.numDependencies=2
25
+package.numDependencies=3
23 26
 package.numTargets=3
24 27
 package.showExtends=true
25 28
 package.showUses=true
@@ -41,13 +44,13 @@ target2.name=MathMethodsTest
41 44
 target2.showInterface=false
42 45
 target2.type=UnitTestTargetJunit4
43 46
 target2.width=110
44
-target2.x=230
45
-target2.y=280
47
+target2.x=270
48
+target2.y=310
46 49
 target3.association=MathMethodsTest
47 50
 target3.height=50
48 51
 target3.name=MathMethods
49 52
 target3.showInterface=false
50 53
 target3.type=ClassTarget
51 54
 target3.width=110
52
-target3.x=200
53
-target3.y=310
55
+target3.x=240
56
+target3.y=340