Lauren Green před 6 roky
rodič
revize
d67c5f1bf7
11 změnil soubory, kde provedl 383 přidání a 185 odebrání
  1. binární
      .DS_Store
  2. 3
    0
      .gitignore
  3. 0
    58
      Adv.java
  4. 0
    94
      AdvCalc.java
  5. 8
    2
      Console.java
  6. 64
    3
      MainApplication.java
  7. 32
    0
      MainMenu.java
  8. 69
    0
      MemoryFunc.java
  9. 19
    0
      SciCalc.java
  10. 109
    0
      SwitchDisplay.java
  11. 79
    28
      package.bluej

binární
.DS_Store Zobrazit soubor


+ 3
- 0
.gitignore Zobrazit soubor

@@ -177,3 +177,6 @@ target/
177 177
 
178 178
 # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
179 179
 hs_err_pid*
180
+
181
+# DS store
182
+*.DS_Store

+ 0
- 58
Adv.java Zobrazit soubor

@@ -1,58 +0,0 @@
1
-
2
-/**
3
-* Scientific Calculator Lab
4
-* Advanced Calculator Scientific Menu Options
5
-*/
6
-public class Adv
7
-{
8
-    // instance variables - replace the example below with your own
9
-    private int memory = 0;
10
- 
11
-    
12
-    /**
13
-    * switch display mode
14
-    * - Binary
15
-    * - Octal
16
-    * - Decimal
17
-    * - Hexadecimal
18
-    */
19
-    public int sampleMethod(int y)
20
-    {
21
-        // Base Mode
22
-        Console.println("Base Mode");
23
-        // Ask for input
24
-        Integer i = Console.getIntegerInput("Enter an integer");
25
-        // Display base options
26
-        // Ask for base option input
27
-        
28
-        return 2;
29
-    }
30
-    
31
-    /**
32
-     * 
33
-    * Memory Mode
34
-    * M+ = add currently displaced value to the value in memory default 0
35
-    * MC = clear memory
36
-    * MCR = display memory
37
-    * 
38
-    */
39
-    public void memory()
40
-    {
41
-        // Memory Mode
42
-        // Ask for input
43
-        // Display memory menu
44
-        // memory option input, if statement
45
-    }
46
-    
47
-    /**
48
-    * switch display mode
49
-    * - Binary
50
-    * - Octal
51
-    * - Decimal
52
-    * - Hexadecimal
53
-    */
54
-    public void toTrig(int y)
55
-    {
56
-        //calls to the trig menu
57
-    }
58
-}

+ 0
- 94
AdvCalc.java Zobrazit soubor

@@ -1,94 +0,0 @@
1
-    
2
-/**
3
-* 4.2 Scientific Calculator Group Project
4
-* Trinh Tong, Lauren Green, Michelle Dimarino
5
-* Advanced Calculator Menu
6
-*/
7
-public class AdvCalc 
8
-{
9
-
10
-    private double memory = 0;
11
-
12
-    /**
13
-     * Switch Display Mode method 
14
-     * -> binary, octal, decimal, hexadecimal
15
-     * switchDisplayMode() rotates through the options
16
-     * switchDisplayMode(String mode) sets the display to the mode given
17
-     */
18
-    public void switchDisplay(String mode)
19
-    {
20
-        int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
21
-        
22
-        Console.println("Display Options" 
23
-                         + "\nBinary: " + null
24
-                         + "\nOctal: " + null
25
-                         + "\nDecimal: " + null
26
-                         + "\nHexadecimal: " + null
27
-                         + "\n");
28
-        
29
-        mode = Console.getStringInput("Enter the base option to display.");
30
-        if (mode.toLowerCase().equals("binary") == true) {
31
-            
32
-        } else if (mode.toLowerCase().equals("octal") == true) {
33
-            
34
-        }
35
-        
36
-
37
-    }
38
-    
39
-    /**
40
-     * Converts the user input into octal and returns a string of that octal.
41
-     */
42
-    public String toOctal(int userInput) {
43
-        
44
-        return Integer.toOctalString(userInput);
45
-        
46
-    }
47
-    /**
48
-     * Store 1 numeric value in memory for recall later
49
-     * M+ = add currently displayed value to the value in memorie (default = 0)
50
-     * MC = reset memory
51
-     * MRC = recall current valie from memory to display
52
-     */
53
-    public void memory()
54
-    {
55
-        // Memory menu
56
-        Console.println("Memory Mode");
57
-        // Ask for input of a number
58
-        double memoryInput = Console.getDoubleInput("Enter a number to store. ");
59
-        // Display memory keys
60
-        Console.println("Memory Options: " 
61
-                         + "\nM+ : adds input to memory"
62
-                         + "\nMC : clears current memory"
63
-                         + "\nMRC : displays current memory input");
64
-                         
65
-        String memorySelect = Console.getStringInput("What would you like to do? (Enter the key)");
66
-
67
-        
68
-        if (memorySelect.equals("M+") == true) {
69
-            // M+
70
-            memory = memoryInput;
71
-            
72
-        } else if (memorySelect.equals("MC") == true) {
73
-            // MC
74
-            memory = 0;
75
-            
76
-        } else if (memorySelect.equals("MCR") == true) {
77
-            // MCR
78
-            Console.println(Double.toString(memory));
79
-        
80
-        }
81
-        
82
-    }  
83
-    
84
-    
85
-    /**
86
-     * To Trig -
87
-     * sends user to trig functions of the calculator
88
-     */
89
-    public void toTrig(int y)
90
-    {
91
-        // calls the trig menu
92
-        
93
-    }
94
-}

+ 8
- 2
Console.java Zobrazit soubor

@@ -23,10 +23,16 @@ public class Console {
23 23
     }
24 24
 
25 25
     public static Integer getIntegerInput(String prompt) {
26
-        return null;
26
+        Scanner scanner = new Scanner(System.in);
27
+        println(prompt);
28
+        Integer userInput = scanner.nextInt();
29
+        return userInput;
27 30
     }
28 31
 
29 32
     public static Double getDoubleInput(String prompt) {
30
-        return null;
33
+        Scanner scanner = new Scanner(System.in);
34
+        println(prompt);
35
+        Double userInput = scanner.nextDouble();
36
+        return userInput;
31 37
     }
32 38
 }

+ 64
- 3
MainApplication.java Zobrazit soubor

@@ -1,17 +1,78 @@
1
- 
2
-
3 1
 /**
4 2
  * Created by leon on 2/9/18.
5 3
  */
4
+import java.util.*;
5
+
6 6
 public class MainApplication {
7
+    
7 8
     public static void main(String[] args) {
9
+        // Create all instances of classes to be used for this program
10
+        MainMenu mainMenu = new MainMenu();
11
+        SciCalc scientificCalc = new SciCalc();
12
+        MemoryFunc memory = new MemoryFunc();
13
+        SwitchDisplay baseChange = new SwitchDisplay();
14
+        
15
+        // Stored memory value should be able to be used throughout whole application
16
+        Double memoryValue = memory.memory;
17
+        
18
+        // if any input = "m", that input now = the memory value
19
+        
20
+        // Menu Input
21
+        String menuInput = " ";
22
+        // Giant while loop that links back to main menu
23
+        while (!menuInput.equals("4")) {
24
+            mainMenu.mainMenuDisplay();
25
+            menuInput = Console.getStringInput("Enter the calculator you want to use by key. (ie. 1 for basic, etc.)");
26
+           
27
+            switch (menuInput) {
28
+                case "1":
29
+                
30
+                    // Sends to basic calculator functions
31
+                    break;
32
+                
33
+                case "2":
34
+                
35
+                    // Sends to Advanced Calculator Functions
36
+                    break;
37
+                
38
+                case "3":
39
+                
40
+                    // Sends to Scientific Calculator Functions
41
+                    // displays the menu for scientific calc
42
+                    scientificCalc.toSciMenu();
43
+                    String sciMenuInput = Console.getStringInput("Enter the function you'd like to use by key.");
44
+                    // if statement to use various calc functions
45
+                    if (sciMenuInput.equals("1")) {
46
+                        // Base Conversions
47
+                        baseChange.switchDisplay();
48
+                        
49
+                    } else if (sciMenuInput.equals("2")) {
50
+                        // Memory
51
+                        memory.memoryMenu();
52
+                    } else if (sciMenuInput.equals("3")) {
53
+                        // To Trig Menu
54
+                        
55
+                    } else {
56
+                        break;
57
+                    }
58
+                    break;
59
+                    
60
+                case "4":
61
+                    // Quits the calculator
62
+                    break;
63
+                }
64
+
65
+        }
66
+
8 67
         Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
68
+        /** String s = Console.getStringInput("Enter a string");
10 69
         Integer i = Console.getIntegerInput("Enter an integer");
11 70
         Double d = Console.getDoubleInput("Enter a double.");
12 71
 
13 72
         Console.println("The user input %s as a string", s);
14 73
         Console.println("The user input %s as a integer", i);
15 74
         Console.println("The user input %s as a d", d);
75
+        */
76
+
16 77
     }
17 78
 }

+ 32
- 0
MainMenu.java Zobrazit soubor

@@ -0,0 +1,32 @@
1
+
2
+/**
3
+ * Scientific Calculator Lab
4
+ * 
5
+ * This class will create the instance of the "Main Menu"
6
+ * 
7
+ * This serves to display the options the user can take to use the calculator
8
+ * 
9
+ * 1: Basic Menu - 4 basic functions + - * /
10
+ * 2: Advanced Menu - Exponents & inverse
11
+ * 3: Scientific Menu - Base Conversions, Memory Functions, Trig Options
12
+ * 
13
+ * The point of this method is for the MAIN Application while loop.
14
+ * Whenever the user opens the calculator OR completes an action
15
+ * in the submenus, the calculator will return to this main menu.
16
+ */
17
+public class MainMenu
18
+{
19
+    /**
20
+     * Method to display the main menu
21
+     */
22
+    
23
+    public void mainMenuDisplay()
24
+    {
25
+        Console.println("Calculator Options:"
26
+                         + "\n1: Basic Calculator (+ - * /)"
27
+                         + "\n2: Advanced Calculator (Exponential Functions)"
28
+                         + "\n3: Scientific Functions (Base Conversion, Memory, Trigonometry)"
29
+                         + "\n4: Exit the calculator");
30
+        
31
+    }
32
+}

+ 69
- 0
MemoryFunc.java Zobrazit soubor

@@ -0,0 +1,69 @@
1
+
2
+/**
3
+
4
+ */
5
+public class MemoryFunc {
6
+    public Double memory;
7
+    public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
8
+
9
+    public MemoryFunc() {
10
+        this.memory = DEFAULT_MEMORY_VALUE;
11
+    }
12
+    /**
13
+     * Menu
14
+     * Clear
15
+     * Print
16
+     * Update
17
+     */
18
+    
19
+    public void memoryMenu() {
20
+        
21
+        Console.println("Memory Menu"
22
+                         + "\n1: M+ - Update stored memory value"
23
+                         + "\n2: nMC - Clear to default memory value"
24
+                         + "\n3: nMCR - Display stored memory value"
25
+                         + "\n4: Cancel - Returns to Main Menu");
26
+                         
27
+        String memoryOpt = "";
28
+        
29
+        while (!memoryOpt.equals("4")) {
30
+            
31
+            memoryOpt = Console.getStringInput("Select option by typing the key. (ie 1 for M+)").toLowerCase();
32
+            
33
+            if (memoryOpt.equals("1")) {
34
+                
35
+                Double newMemory = Console.getDoubleInput("Enter the value to store");
36
+                updateMemory(newMemory);
37
+                break;
38
+                
39
+            } else if (memoryOpt.equals("2")) {
40
+                
41
+                clearMemory();
42
+                break;
43
+                
44
+            } else if (memoryOpt.equals("3")) {
45
+                
46
+                displayMemory();
47
+                break;
48
+                
49
+            } else {
50
+                
51
+                Console.println("Invalid Option");
52
+                
53
+            }
54
+        }
55
+    }
56
+    
57
+    public void updateMemory(Double memoryInput) {
58
+        this.memory = memoryInput;
59
+    }
60
+    
61
+    public void clearMemory() {
62
+        this.memory = DEFAULT_MEMORY_VALUE;
63
+    }
64
+    
65
+    public void displayMemory() {
66
+        Console.println(memory.toString());
67
+    }
68
+    
69
+}

+ 19
- 0
SciCalc.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+
2
+/**
3
+* 4.2 Scientific Calculator Group Project
4
+* Trinh Tong, Lauren Green, Michelle Dimarino
5
+* Advanced Calculator Menu
6
+*/
7
+public class SciCalc 
8
+{
9
+
10
+
11
+    public void toSciMenu() {
12
+        Console.println("Scientific Calculator Functions:"
13
+                         + "\n1: Base Conversion - Converts input to selected base"
14
+                         + "\n2: Memory - Memory functions"
15
+                         + "\n3: Trigonometry "
16
+                         + "\n4: Return to Main Menu");        
17
+        
18
+    }
19
+}

+ 109
- 0
SwitchDisplay.java Zobrazit soubor

@@ -0,0 +1,109 @@
1
+
2
+/**
3
+ * Write a description of class SwitchDisplay here.
4
+ *
5
+ * Scientific Calculator Lab
6
+ * 
7
+ * Brings up the switch display menu
8
+ * Binary
9
+ * Octal
10
+ * Decimal
11
+ * Hexadecimal
12
+ * 
13
+ * Changes the mode for EVERYTHING
14
+ * 
15
+ * Find a way to store the input and the input as a diff base
16
+ * then whenever the base is changed, display the base.
17
+ * pass the input into the methods to return the string.
18
+ * EVERY TIME AN INPUT IS PLACED, IT WILL BE DISPLAYED AS AN OCTAL
19
+ * boolean baseChange == true; 
20
+ *      display the changed display
21
+ */
22
+public class SwitchDisplay
23
+{
24
+    // instance variables - replace the example below with your own
25
+
26
+    /**
27
+     * Switch Display Mode method 
28
+     * -> binary, octal, decimal, hexadecimal
29
+     * switchDisplayMode() rotates through the options
30
+     * switchDisplayMode(String mode) sets the display to the mode given
31
+     */
32
+    
33
+    public void switchDisplay()
34
+    {
35
+        String mode = "Invalid Input";
36
+        
37
+        while (mode.equals("Invalid Input")) {
38
+            int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
39
+    
40
+            Console.println("Display Options" 
41
+                             + "\n1: Binary"
42
+                             + "\n2: Octal"
43
+                             + "\n3: Decimal"
44
+                             + "\n4: Hexadecimal"
45
+                             + "\n5: Cancel - returns to Main Menu");
46
+                             
47
+            // Asks for the mode
48
+            mode = Console.getStringInput("Enter the desired display mode: ");
49
+            
50
+            String convertedInput = switchDisplayOutput(mode, baseInput);
51
+            
52
+            Console.println(convertedInput); 
53
+            // passes to switchDisplayOutput(mode) >> returns string
54
+            // displays the returned string
55
+            // while loops !cancel
56
+        }
57
+                         
58
+    }
59
+    
60
+    public String switchDisplayOutput(String mode, int baseInput) {
61
+        switch (mode) {
62
+            case "1":
63
+                return toBinary(baseInput);
64
+                
65
+            case "2":
66
+                return toOctal(baseInput);
67
+                
68
+            case "3":
69
+                return toDecimal(baseInput);
70
+                
71
+            case "4":
72
+                return toHexa(baseInput);
73
+                
74
+            case "5":
75
+                return mode;
76
+                
77
+            default:
78
+                return "Invalid Input";
79
+        }
80
+    }
81
+    
82
+    /**
83
+     * Converts the user input into corresponding base types
84
+     */
85
+    
86
+    public String toBinary(int userInput) {
87
+        
88
+        return Integer.toBinaryString(userInput);
89
+        
90
+    }
91
+    
92
+    public String toOctal(int userInput) {
93
+        
94
+        return Integer.toOctalString(userInput);
95
+        
96
+    }
97
+    
98
+    public String toDecimal(int userInput) {
99
+        
100
+        return Integer.toBinaryString(userInput);
101
+        
102
+    }
103
+    
104
+    public String toHexa(int userInput) {
105
+    
106
+        return Integer.toHexString(userInput);
107
+    
108
+    }
109
+}

+ 79
- 28
package.bluej Zobrazit soubor

@@ -1,23 +1,51 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
2
+dependency1.from=MainMenu
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=AdvCalc
5
+<<<<<<< HEAD
6
+dependency2.from=SciCalc
6 7
 dependency2.to=Console
7 8
 dependency2.type=UsesDependency
8
-dependency3.from=Adv
9
+dependency3.from=MemoryFunc
9 10
 dependency3.to=Console
10 11
 dependency3.type=UsesDependency
11
-dependency4.from=Basic
12
+dependency4.from=SwitchDisplay
12 13
 dependency4.to=Console
13 14
 dependency4.type=UsesDependency
14
-dependency5.from=Trig
15
-dependency5.to=Console
15
+editor.fx.0.height=0
16
+editor.fx.0.width=0
17
+editor.fx.0.x=0
18
+editor.fx.0.y=0
19
+=======
20
+dependency2.from=SwitchDisplay
21
+dependency2.to=Console
22
+dependency2.type=UsesDependency
23
+dependency3.from=SciCalc
24
+dependency3.to=Console
25
+dependency3.type=UsesDependency
26
+dependency4.from=MainApplication
27
+dependency4.to=MainMenu
28
+dependency4.type=UsesDependency
29
+dependency5.from=MainApplication
30
+dependency5.to=SciCalc
16 31
 dependency5.type=UsesDependency
17
-editor.fx.0.height=958
18
-editor.fx.0.width=904
19
-editor.fx.0.x=759
20
-editor.fx.0.y=23
32
+dependency6.from=MainApplication
33
+dependency6.to=MemoryFunc
34
+dependency6.type=UsesDependency
35
+dependency7.from=MainApplication
36
+dependency7.to=SwitchDisplay
37
+dependency7.type=UsesDependency
38
+dependency8.from=MainApplication
39
+dependency8.to=Console
40
+dependency8.type=UsesDependency
41
+dependency9.from=MemoryFunc
42
+dependency9.to=Console
43
+dependency9.type=UsesDependency
44
+editor.fx.0.height=722
45
+editor.fx.0.width=1120
46
+editor.fx.0.x=320
47
+editor.fx.0.y=119
48
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
21 49
 objectbench.height=214
22 50
 objectbench.width=706
23 51
 package.divider.horizontal=0.6
@@ -25,11 +53,15 @@ package.divider.vertical=0.720253164556962
25 53
 package.editor.height=562
26 54
 package.editor.width=604
27 55
 package.editor.x=35
28
-package.editor.y=60
29
-package.frame.height=848
30
-package.frame.width=730
31
-package.numDependencies=5
32
-package.numTargets=6
56
+package.editor.y=59
57
+package.frame.height=759
58
+package.frame.width=619
59
+<<<<<<< HEAD
60
+package.numDependencies=4
61
+=======
62
+package.numDependencies=9
63
+package.numTargets=8
64
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
33 65
 package.showExtends=true
34 66
 package.showUses=true
35 67
 project.charset=UTF-8
@@ -46,26 +78,31 @@ target1.width=80
46 78
 target1.x=90
47 79
 target1.y=10
48 80
 target2.height=50
49
-target2.name=Basic
81
+target2.name=SciCalc
50 82
 target2.showInterface=false
51 83
 target2.type=ClassTarget
52 84
 target2.width=80
53
-target2.x=320
54
-target2.y=180
85
+target2.x=10
86
+target2.y=280
55 87
 target3.height=50
56
-target3.name=Adv
88
+target3.name=MemoryFunc
57 89
 target3.showInterface=false
58 90
 target3.type=ClassTarget
59
-target3.width=80
60
-target3.x=180
61
-target3.y=10
91
+target3.width=110
92
+<<<<<<< HEAD
93
+target3.x=150
94
+target3.y=410
95
+=======
96
+target3.x=210
97
+target3.y=350
98
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
62 99
 target4.height=50
63 100
 target4.name=Console
64 101
 target4.showInterface=false
65 102
 target4.type=ClassTarget
66 103
 target4.width=80
67
-target4.x=80
68
-target4.y=200
104
+target4.x=70
105
+target4.y=170
69 106
 target5.height=50
70 107
 target5.name=Trig
71 108
 target5.showInterface=false
@@ -74,9 +111,23 @@ target5.width=80
74 111
 target5.x=320
75 112
 target5.y=70
76 113
 target6.height=50
77
-target6.name=MainApplication
114
+target6.name=SwitchDisplay
78 115
 target6.showInterface=false
79 116
 target6.type=ClassTarget
80
-target6.width=120
81
-target6.x=70
82
-target6.y=70
117
+target6.width=110
118
+target6.x=80
119
+target6.y=350
120
+target7.height=50
121
+target7.name=MainMenu
122
+target7.showInterface=false
123
+target7.type=ClassTarget
124
+target7.width=90
125
+target7.x=70
126
+target7.y=10
127
+target8.height=50
128
+target8.name=MainApplication
129
+target8.showInterface=false
130
+target8.type=ClassTarget
131
+target8.width=120
132
+target8.x=70
133
+target8.y=70