Bläddra i källkod

getCommand has been added, to use start your method with getCommand(userInput)

Jonathan Hinds 6 år sedan
förälder
incheckning
7bd79b5158
4 ändrade filer med 134 tillägg och 46 borttagningar
  1. 83
    0
      Calculations.java
  2. 19
    18
      Console.java
  3. 7
    7
      MainApplication.java
  4. 25
    21
      package.bluej

+ 83
- 0
Calculations.java Visa fil

@@ -0,0 +1,83 @@
1
+import java.util.ArrayList;
2
+
3
+public class Calculations
4
+{
5
+    public static ArrayList<String> library = new ArrayList<String>();
6
+    
7
+    public Calculations(){
8
+   
9
+    library.add("multiply");
10
+    library.add("divide");
11
+    library.add("subtract");
12
+    library.add("add");
13
+    library.add("COS");
14
+    library.add("SIN");
15
+    library.add("TAN");
16
+    library.add("invertS");
17
+    library.add("invertN");
18
+    library.add("factorial");
19
+    library.add("switchunit");
20
+    library.add("clear");
21
+    library.add("storeM");
22
+    library.add("resetM");
23
+    library.add("recallM");
24
+    library.add("displayM");
25
+        
26
+    }
27
+
28
+    public static String getCommand(String userInput)
29
+    {
30
+        boolean foundCommand = false;
31
+        String command = "";
32
+        String[] inputArr = userInput.split(" ");
33
+        for(int i = 0; i < library.size(); i ++)
34
+        {
35
+            String currCommand = library.get(i);
36
+            if(currCommand.equalsIgnoreCase(inputArr[0]))
37
+            {
38
+                command = currCommand;
39
+                foundCommand = true;
40
+                break;
41
+            }
42
+        }
43
+        
44
+        switch(command)
45
+        {
46
+            case "multiply":
47
+                Multiply(userInput);
48
+            break;
49
+            
50
+            case "divide":
51
+                Divide(userInput);
52
+            break;
53
+            
54
+            case "add":
55
+                Add(userInput);
56
+            break;
57
+            
58
+            case "subtract":
59
+                Subtract(userInput);
60
+            break;
61
+            
62
+            case "invertS":
63
+                InvertSign(userInput);
64
+            break;
65
+            
66
+            case "invertN":
67
+                InvertNumber(userInput);
68
+            break;   
69
+            
70
+            case "clear":
71
+                Clear();
72
+            break;
73
+        }
74
+        
75
+        return null;
76
+    }
77
+    
78
+    public static String InvertSign(String userInput)
79
+    {
80
+        
81
+    }
82
+   
83
+}

+ 19
- 18
Console.java Visa fil

@@ -7,26 +7,27 @@ import java.util.Scanner;
7 7
  */
8 8
 public class Console {
9 9
 
10
-    public static void print(String output, Object... args) {
11
-        System.out.printf(output, args);
12
-    }
10
+    
11
+    //public static void print(String output, Object... args) {
12
+    //    System.out.printf(output, args);
13
+    //}
13 14
 
14
-    public static void println(String output, Object... args) {
15
-        print(output + "\n", args);
16
-    }
15
+    //public static void println(String output, Object... args) {
16
+    //    print(output + "\n", args);
17
+    //}
17 18
 
18
-    public static String getStringInput(String prompt) {
19
-        Scanner scanner = new Scanner(System.in);
20
-        println(prompt);
21
-        String userInput = scanner.nextLine();
22
-        return userInput;
23
-    }
19
+    //public static String getStringInput(String prompt) {
20
+    //    Scanner scanner = new Scanner(System.in);
21
+    //    println(prompt);
22
+    //    String userInput = scanner.nextLine();
23
+    //    return userInput;
24
+    //}
24 25
 
25
-    public static Integer getIntegerInput(String prompt) {
26
-        return null;
27
-    }
26
+    //public static Integer getIntegerInput(String prompt) {
27
+    //    return null;
28
+    //}
28 29
 
29
-    public static Double getDoubleInput(String prompt) {
30
-        return null;
31
-    }
30
+    //public static Double getDoubleInput(String prompt) {
31
+    //    return null;
32
+    //}
32 33
 }

+ 7
- 7
MainApplication.java Visa fil

@@ -5,13 +5,13 @@
5 5
  */
6 6
 public class MainApplication {
7 7
     public static void main(String[] args) {
8
-        Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
10
-        Integer i = Console.getIntegerInput("Enter an integer");
11
-        Double d = Console.getDoubleInput("Enter a double.");
8
+        //Console.println("Welcome to my calculator!");
9
+        //String s = Console.getStringInput("Enter a string");
10
+        //Integer i = Console.getIntegerInput("Enter an integer");
11
+        //Double d = Console.getDoubleInput("Enter a double.");
12 12
 
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);
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 16
     }
17 17
 }

+ 25
- 21
package.bluej Visa fil

@@ -1,23 +1,20 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
3
-dependency1.to=Console
4
-dependency1.type=UsesDependency
5
-editor.fx.0.height=722
2
+editor.fx.0.height=717
6 3
 editor.fx.0.width=800
7
-editor.fx.0.x=640
8
-editor.fx.0.y=23
9
-objectbench.height=214
4
+editor.fx.0.x=497
5
+editor.fx.0.y=-827
6
+objectbench.height=200
10 7
 objectbench.width=595
11 8
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
9
+package.divider.vertical=0.6854103343465046
10
+package.editor.height=444
14 11
 package.editor.width=493
15 12
 package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
13
+package.editor.y=23
14
+package.frame.height=716
18 15
 package.frame.width=619
19
-package.numDependencies=1
20
-package.numTargets=2
16
+package.numDependencies=0
17
+package.numTargets=3
21 18
 package.showExtends=true
22 19
 package.showUses=true
23 20
 project.charset=UTF-8
@@ -27,16 +24,23 @@ readme.width=47
27 24
 readme.x=10
28 25
 readme.y=10
29 26
 target1.height=50
30
-target1.name=Console
27
+target1.name=Calculations
31 28
 target1.showInterface=false
32 29
 target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
30
+target1.width=100
31
+target1.x=120
32
+target1.y=150
36 33
 target2.height=50
37
-target2.name=MainApplication
34
+target2.name=Console
38 35
 target2.showInterface=false
39 36
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
37
+target2.width=80
38
+target2.x=20
39
+target2.y=150
40
+target3.height=50
41
+target3.name=MainApplication
42
+target3.showInterface=false
43
+target3.type=ClassTarget
44
+target3.width=120
45
+target3.x=70
46
+target3.y=70