Преглед на файлове

Merge branch 'master' of https://git.zipcode.rocks/cdunni/ZCW-MacroLabs-OOP-ScientificCalculator

jacobs files
Connor Dunnigan преди 6 години
родител
ревизия
d99c850dcd
променени са 5 файла, в които са добавени 249 реда и са изтрити 25 реда
  1. 11
    3
      MainApplication.java
  2. 29
    0
      NumSystemsConverter.java
  3. 104
    0
      SwitchModes.java
  4. 45
    0
      UpdateDisplay.java
  5. 60
    22
      package.bluej

+ 11
- 3
MainApplication.java Целия файл

@@ -5,13 +5,21 @@
5 5
  */
6 6
 public class MainApplication {
7 7
     public static void main(String[] args) {
8
+        
9
+        double Display = 0;
10
+        int num_system = 1;
11
+        double memory = 0;
12
+        
8 13
         Console.println("Welcome to my calculator!");
14
+        Console.println("Choose your option : ");
15
+        
9 16
         String s = Console.getStringInput("Enter a string");
17
+        
18
+        while (s != "quit") {
19
+            
10 20
         Integer i = Console.getIntegerInput("Enter an integer");
11 21
         Double d = Console.getDoubleInput("Enter a double.");
22
+    }
12 23
 
13
-        Console.println("The user input %s as a string", s);
14
-        Console.println("The user input %s as a integer", i);
15
-        Console.println("The user input %s as a d", d);
16 24
     }
17 25
 }

+ 29
- 0
NumSystemsConverter.java Целия файл

@@ -0,0 +1,29 @@
1
+public class NumSystemsConverter
2
+{
3
+    // display mode is sent along with displayNumber, could also be defined globally)
4
+    public String updateDisplayNumber(double displayNumber,int mode){
5
+        String str="";
6
+        switch(mode) {
7
+            case 1:{
8
+                str=Double.toString(displayNumber);
9
+                break;
10
+            }
11
+            case 2:{
12
+                str=Long.toBinaryString(Double.doubleToRawLongBits(displayNumber));
13
+                break;
14
+            }
15
+            case 3:{
16
+                str=Double.toHexString(displayNumber);
17
+                break;
18
+            }
19
+            case 4:{
20
+                double fraction = (displayNumber%1);
21
+                double integral = (displayNumber-fraction);
22
+                str=Integer.toOctalString((int)integral)+"."+Integer.toOctalString((int)(fraction+.5));
23
+                break;
24
+            }
25
+        }
26
+        return str;
27
+    }
28
+}
29
+

+ 104
- 0
SwitchModes.java Целия файл

@@ -0,0 +1,104 @@
1
+
2
+/**
3
+ * Write a description of class SwitchModes here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class SwitchModes
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int displayMode=1;
12
+    private int unitMode=1;
13
+
14
+    SwitchModes sm = new SwitchModes();
15
+
16
+    public int getDisplayMode(){
17
+        return displayMode;
18
+    }
19
+
20
+    public void setDisplayMode(int mode){
21
+        displayMode=mode;
22
+    }
23
+
24
+    public int getUnitMode(){
25
+        return unitMode;
26
+    }
27
+
28
+    public void setUnitMode(int mode){
29
+        unitMode=mode;
30
+    }
31
+
32
+    /**
33
+     * Constructor for objects of class SwitchModes
34
+     */
35
+    public SwitchModes()
36
+    {
37
+        // initialise instance variables
38
+    }
39
+
40
+    /**
41
+     * An example of a method - replace this comment with your own
42
+     *
43
+     * @param  y  a sample parameter for a method
44
+     * @return    the sum of x and y
45
+     */
46
+
47
+    public void switchDisplayMode (String mode){
48
+        mode.toLowerCase();
49
+        switch (mode) {
50
+            case "hex": { 
51
+                displayMode=1;
52
+                // call update display
53
+                break;
54
+            }
55
+            case "bin": { 
56
+                displayMode=2;
57
+                // call update display
58
+                break;
59
+            }
60
+            case "dec": { 
61
+                displayMode=3;
62
+                // call update display
63
+                break;
64
+            }case "oct": { 
65
+                displayMode=4;
66
+                // call update display
67
+                break;
68
+            }
69
+        }
70
+    }
71
+
72
+    public void switchDisplayMode(){
73
+        if (displayMode==4){
74
+            displayMode=1;
75
+            // call update display
76
+        } 
77
+        else {
78
+            displayMode++;
79
+            // call update display
80
+        }
81
+
82
+    }
83
+
84
+    public void switchUnitsMode (String mode){
85
+        if (mode.toLowerCase()=="degrees") {
86
+            unitMode=1;
87
+
88
+        } else if(mode.toLowerCase()=="radians")
89
+            unitMode=2;
90
+
91
+    }
92
+    public void switchUnitsMode(){
93
+        if (unitMode==2){
94
+            unitMode=1;
95
+            // call update display
96
+        } 
97
+        else {
98
+            unitMode++;
99
+            // call update display
100
+        }
101
+
102
+    }
103
+
104
+}

+ 45
- 0
UpdateDisplay.java Целия файл

@@ -0,0 +1,45 @@
1
+
2
+/**
3
+ * Write a description of class UpdateDisplay here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class UpdateDisplay
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class UpdateDisplay
15
+     */
16
+    public UpdateDisplay(Double displayNumber)
17
+    {
18
+       
19
+        // initialise instance variables
20
+        //x = 0;
21
+    }
22
+
23
+    /**
24
+     * An example of a method - replace this comment with your own
25
+     *
26
+     * @param  y  a sample parameter for a method
27
+     * @return    the sum of x and y
28
+     */
29
+    
30
+    SwitchModes sm = new SwitchModes();
31
+    
32
+    public String UpdateDisplay(Double displayNumber)
33
+    {
34
+     String str="";
35
+     
36
+     
37
+     // update number system based on display mode variable (see SwitchModes class)
38
+     
39
+     
40
+     
41
+     return str;   
42
+    }
43
+}
44
+
45
+

+ 60
- 22
package.bluej Целия файл

@@ -2,22 +2,25 @@
2 2
 dependency1.from=MainApplication
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=640
5
+dependency2.from=UpdateDisplay
6
+dependency2.to=SwitchModes
7
+dependency2.type=UsesDependency
8
+editor.fx.0.height=717
9
+editor.fx.0.width=1280
10
+editor.fx.0.x=0
8 11
 editor.fx.0.y=23
9
-objectbench.height=214
10
-objectbench.width=595
12
+objectbench.height=92
13
+objectbench.width=1256
11 14
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
14
-package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
18
-package.frame.width=619
19
-package.numDependencies=1
20
-package.numTargets=2
15
+package.divider.vertical=0.8495440729483282
16
+package.editor.height=552
17
+package.editor.width=1154
18
+package.editor.x=0
19
+package.editor.y=23
20
+package.frame.height=716
21
+package.frame.width=1280
22
+package.numDependencies=2
23
+package.numTargets=7
21 24
 package.showExtends=true
22 25
 package.showUses=true
23 26
 project.charset=UTF-8
@@ -27,16 +30,51 @@ readme.width=47
27 30
 readme.x=10
28 31
 readme.y=10
29 32
 target1.height=50
30
-target1.name=Console
33
+target1.name=UpdateDisplay
31 34
 target1.showInterface=false
32 35
 target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
36
+target1.width=120
37
+target1.x=130
38
+target1.y=130
36 39
 target2.height=50
37
-target2.name=MainApplication
40
+target2.name=Memory
38 41
 target2.showInterface=false
39 42
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
43
+target2.width=80
44
+target2.x=190
45
+target2.y=10
46
+target3.height=50
47
+target3.name=Console
48
+target3.showInterface=false
49
+target3.type=ClassTarget
50
+target3.width=80
51
+target3.x=80
52
+target3.y=200
53
+target4.height=50
54
+target4.name=SwitchModes
55
+target4.showInterface=false
56
+target4.type=ClassTarget
57
+target4.width=110
58
+target4.x=10
59
+target4.y=130
60
+target5.height=50
61
+target5.name=NumSystemsConverter
62
+target5.showInterface=false
63
+target5.type=ClassTarget
64
+target5.width=170
65
+target5.x=10
66
+target5.y=320
67
+target6.height=50
68
+target6.name=SciCalculator
69
+target6.showInterface=false
70
+target6.type=ClassTarget
71
+target6.width=110
72
+target6.x=70
73
+target6.y=10
74
+target7.height=50
75
+target7.name=MainApplication
76
+target7.showInterface=false
77
+target7.type=ClassTarget
78
+target7.width=120
79
+target7.x=70
80
+target7.y=70