Parcourir la source

Updated methods

Trinh Tong il y a 6 ans
Parent
révision
a8b6847c56
3 fichiers modifiés avec 72 ajouts et 36 suppressions
  1. 48
    8
      MainApplication.java
  2. 7
    16
      SciCalc.java
  3. 17
    12
      SwitchDisplay.java

+ 48
- 8
MainApplication.java Voir le fichier

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

+ 7
- 16
SciCalc.java Voir le fichier

@@ -10,21 +10,12 @@
10 10
 */
11 11
 public class SciCalc 
12 12
 {
13
-    public void toSwitchDisplay() {
14
-        SwitchDisplay switchDisplayMenu =  new SwitchDisplay();
15
-    }
16
-    
17
-    public void toMemory() {
18
-        MemoryFunc memoryMenu = new MemoryFunc();
19
-    }
20
-    
21
-    /**
22
-     * To Trig -
23
-     * sends user to trig functions of the calculator
24
-     */
25
-     public void toTrig(int y)
26
-    {
27
-        // calls the trig menu
28
-        Trig trigMenu = new Trig();
13
+    public void toSciMenu() {
14
+        Console.println("Scientific Calculator Functions:"
15
+                         + "\n1: Base Conversion - Converts input to selected base"
16
+                         + "\n2: Memory - Memory functions"
17
+                         + "\n3: Trigonometry "
18
+                         + "\n4: Return to Main Menu");        
19
+        
29 20
     }
30 21
 }

+ 17
- 12
SwitchDisplay.java Voir le fichier

@@ -32,16 +32,18 @@ public class SwitchDisplay
32 32
     
33 33
     public void switchDisplay()
34 34
     {
35
-        String mode = "";
36
-        while (!mode.equals("cancel")) {
35
+        String mode = "Invalid Input";
36
+        
37
+        while (mode.equals("Invalid Input")) {
37 38
             int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
38 39
     
39 40
             Console.println("Display Options" 
40
-                             + "\nBinary"
41
-                             + "\nOctal"
42
-                             + "\nDecimal"
43
-                             + "\nHexadecimal"
44
-                             + "\nCancel: returns to Main Menu");
41
+                             + "\n1: Binary"
42
+                             + "\n2: Octal"
43
+                             + "\n3: Decimal"
44
+                             + "\n4: Hexadecimal"
45
+                             + "\n5: Cancel - returns to Main Menu");
46
+                             
45 47
             // Asks for the mode
46 48
             mode = Console.getStringInput("Enter the desired display mode: ");
47 49
             
@@ -57,21 +59,24 @@ public class SwitchDisplay
57 59
     
58 60
     public String switchDisplayOutput(String mode, int baseInput) {
59 61
         switch (mode) {
60
-            case "binary":
62
+            case "1":
61 63
                 return toBinary(baseInput);
62 64
                 
63
-            case "octal":
65
+            case "2":
64 66
                 return toOctal(baseInput);
65 67
                 
66
-            case "decimal":
68
+            case "3":
67 69
                 return toDecimal(baseInput);
68 70
                 
69
-            case "hexadecimal":
71
+            case "4":
70 72
                 return toHexa(baseInput);
71 73
                 
74
+            case "5":
75
+                return mode;
76
+                
72 77
             default:
73 78
                 return "Invalid Input";
74
-            }
79
+        }
75 80
     }
76 81
     
77 82
     /**