Trinh Tong пре 6 година
родитељ
комит
5b0bd69a84
7 измењених фајлова са 229 додато и 164 уклоњено
  1. 8
    2
      Console.java
  2. 64
    3
      MainApplication.java
  3. 5
    13
      MainMenu.java
  4. 57
    36
      MemoryFunc.java
  5. 7
    82
      SciCalc.java
  6. 45
    25
      SwitchDisplay.java
  7. 43
    3
      package.bluej

+ 8
- 2
Console.java Прегледај датотеку

@@ -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 Прегледај датотеку

@@ -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
 }

+ 5
- 13
MainMenu.java Прегледај датотеку

@@ -16,25 +16,17 @@
16 16
  */
17 17
 public class MainMenu
18 18
 {
19
-    // instance variables - replace the example below with your own
20
-    private int x;
21
-
22
-    /**
23
-     * Constructor for objects of class MainMenu
24
-     */
25
-    public MainMenu()
26
-    {
27
-        // initialise instance variables
28
-        x = 0;
29
-    }
30
-
31 19
     /**
32 20
      * Method to display the main menu
33 21
      */
34 22
     
35 23
     public void mainMenuDisplay()
36 24
     {
37
-        // put your code here
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");
38 30
         
39 31
     }
40 32
 }

+ 57
- 36
MemoryFunc.java Прегледај датотеку

@@ -1,48 +1,69 @@
1 1
 
2 2
 /**
3
- * Scientific Calculator Lab
4
- * Trinh Tong
5
- * Memory Class
3
+
6 4
  */
7
-public class MemoryFunc
8
-{
9
-    // instance variables - replace the example below with your own
10
-    private double memory = 0;
5
+public class MemoryFunc {
6
+    public Double memory;
7
+    public static final Double DEFAULT_MEMORY_VALUE = new Double(0);
11 8
 
9
+    public MemoryFunc() {
10
+        this.memory = DEFAULT_MEMORY_VALUE;
11
+    }
12 12
     /**
13
-     * Store 1 numeric value in memory for recall later
14
-     * M+ = add currently displayed value to the value in memorie (default = 0)
15
-     * MC = reset memory
16
-     * MRC = recall current valie from memory to display
13
+     * Menu
14
+     * Clear
15
+     * Print
16
+     * Update
17 17
      */
18
-    public void memory()
19
-    {
20
-        // Memory menu
21
-        Console.println("Memory Mode");
22
-        // Ask for input of a number
23
-        double memoryInput = Console.getDoubleInput("Enter a number to store. ");
24
-        // Display memory keys
25
-        Console.println("Memory Options: " 
26
-                         + "\nM+ : adds input to memory"
27
-                         + "\nMC : clears current memory"
28
-                         + "\nMRC : displays current memory input");
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");
29 26
                          
30
-        String memorySelect = Console.getStringInput("What would you like to do? (Enter the key)");
31
-
27
+        String memoryOpt = "";
32 28
         
33
-        if (memorySelect.equals("M+") == true) {
34
-            // M+
35
-            memory = memoryInput;
29
+        while (!memoryOpt.equals("4")) {
36 30
             
37
-        } else if (memorySelect.equals("MC") == true) {
38
-            // MC
39
-            memory = 0;
31
+            memoryOpt = Console.getStringInput("Select option by typing the key. (ie 1 for M+)").toLowerCase();
40 32
             
41
-        } else if (memorySelect.equals("MCR") == true) {
42
-            // MCR
43
-            Console.println(Double.toString(memory));
44
-        
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
+            }
45 54
         }
46
-        
47
-    }  
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
+    
48 69
 }

+ 7
- 82
SciCalc.java Прегледај датотеку

@@ -7,88 +7,13 @@
7 7
 public class SciCalc 
8 8
 {
9 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 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
+        
93 18
     }
94 19
 }

+ 45
- 25
SwitchDisplay.java Прегледај датотеку

@@ -29,34 +29,54 @@ public class SwitchDisplay
29 29
      * switchDisplayMode() rotates through the options
30 30
      * switchDisplayMode(String mode) sets the display to the mode given
31 31
      */
32
-    public void switchDisplay(String mode)
32
+    
33
+    public void switchDisplay()
33 34
     {
34
-        int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
35
-        // try catch for int vs double or other input
36
-        Console.println("Display Options" 
37
-                         + "\nBinary"
38
-                         + "\nOctal"
39
-                         + "\nDecimal"
40
-                         + "\nHexadecimal"
41
-                         + "\nCancel: returns to Main Menu");
42
-        // Accepts next input to display mode.
43
-        mode = Console.getStringInput("Enter the base option to display.").toLowerCase();
35
+        String mode = "Invalid Input";
44 36
         
45
-        if (mode.equals("binary") == true) {
46
-            Console.println(baseInput + "in binary: " + toBinary(baseInput));
47
-        } else if (mode.equals("octal") == true) {
48
-            Console.println(baseInput + "in octal: " + toOctal(baseInput));
49
-        } else if (mode.equals("decimal") == true) {
50
-            Console.println(baseInput + "in decimal: " + baseInput);
51
-        } else if (mode.equals("hexadecimal") == true) {
52
-            Console.println(baseInput + "in hexadecimal: " + toHexa(baseInput));
53
-        } else if (mode.equals("cancel") == true) {
54
-            Console.println("Returning to Main Menu");
55
-            // calls back to main application menu
56
-        } else {
57
-            Console.println("Invalid input.");
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";
58 79
         }
59
-        
60 80
     }
61 81
     
62 82
     /**

+ 43
- 3
package.bluej Прегледај датотеку

@@ -1,7 +1,8 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
2
+dependency1.from=MainMenu
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
+<<<<<<< HEAD
5 6
 dependency2.from=SciCalc
6 7
 dependency2.to=Console
7 8
 dependency2.type=UsesDependency
@@ -15,17 +16,51 @@ editor.fx.0.height=0
15 16
 editor.fx.0.width=0
16 17
 editor.fx.0.x=0
17 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
31
+dependency5.type=UsesDependency
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
+>>>>>>> trinhsCalc
18 49
 objectbench.height=214
19 50
 objectbench.width=595
20 51
 package.divider.horizontal=0.6
21 52
 package.divider.vertical=0.6847360912981455
22 53
 package.editor.height=473
23
-package.editor.width=477
54
+package.editor.width=493
24 55
 package.editor.x=35
25
-package.editor.y=60
56
+package.editor.y=59
26 57
 package.frame.height=759
27 58
 package.frame.width=619
59
+<<<<<<< HEAD
28 60
 package.numDependencies=4
61
+=======
62
+package.numDependencies=9
63
+>>>>>>> trinhsCalc
29 64
 package.numTargets=8
30 65
 package.showExtends=true
31 66
 package.showUses=true
@@ -54,8 +89,13 @@ target3.name=MemoryFunc
54 89
 target3.showInterface=false
55 90
 target3.type=ClassTarget
56 91
 target3.width=110
92
+<<<<<<< HEAD
57 93
 target3.x=150
58 94
 target3.y=410
95
+=======
96
+target3.x=210
97
+target3.y=350
98
+>>>>>>> trinhsCalc
59 99
 target4.height=50
60 100
 target4.name=Console
61 101
 target4.showInterface=false