Преглед изворни кода

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

Elliott Stansbury пре 6 година
родитељ
комит
78e04fc100
3 измењених фајлова са 110 додато и 14 уклоњено
  1. 83
    10
      Calculations.java
  2. 20
    4
      MainApplication.java
  3. 7
    0
      package.bluej

+ 83
- 10
Calculations.java Прегледај датотеку

@@ -2,6 +2,7 @@ import java.util.ArrayList;
2 2
 
3 3
 public class Calculations
4 4
 {
5
+    public static Console console = new Console();
5 6
     public static ArrayList<String> library = new ArrayList<String>();
6 7
     
7 8
     public Calculations(){
@@ -25,10 +26,12 @@ public class Calculations
25 26
         
26 27
     }
27 28
 
28
-    public static String getCommand(String userInput)
29
+    public static void getCommand(String userInput)
29 30
     {
30 31
         boolean foundCommand = false;
31 32
         String command = "";
33
+        String result = "";
34
+        
32 35
         String[] inputArr = userInput.split(" ");
33 36
         for(int i = 0; i < library.size(); i ++)
34 37
         {
@@ -44,40 +47,110 @@ public class Calculations
44 47
         switch(command)
45 48
         {
46 49
             case "multiply":
47
-                Multiply(userInput);
50
+                result = Multiply(userInput);
48 51
             break;
49 52
             
50 53
             case "divide":
51
-                Divide(userInput);
54
+                result = Divide(userInput);
52 55
             break;
53 56
             
54 57
             case "add":
55
-                Add(userInput);
58
+                result = Add(userInput);
56 59
             break;
57 60
             
58 61
             case "subtract":
59
-                Subtract(userInput);
62
+                result = Subtract(userInput);
60 63
             break;
61 64
             
62 65
             case "invertS":
63
-                InvertSign(userInput);
66
+                result = InvertSign(userInput);
64 67
             break;
65 68
             
66 69
             case "invertN":
67
-                InvertNumber(userInput);
70
+                result = InvertNumber(userInput);
68 71
             break;   
69 72
             
70 73
             case "clear":
71 74
                 Clear();
72 75
             break;
73 76
         }
74
-        
77
+        System.out.println(result);
78
+        //return result;
79
+    }
80
+    
81
+    public static String Multiply(String userInput)
82
+    {
83
+        //take in a string
84
+        //take the numbers out of the string
85
+        //convert them to doubles
86
+        //perform the operation
87
+        //convert to string
88
+        //return string
89
+        return null;
90
+    }
91
+
92
+    public static String Divide(String userInput)
93
+    {
94
+        //take in a string
95
+        //take the numbers out of the string
96
+        //convert them to doubles
97
+        //perform the operation
98
+        //convert to string
99
+        //return string
100
+        return null;
101
+    } 
102
+
103
+        public static String Add(String userInput)
104
+    {
105
+        //take in a string
106
+        //take the numbers out of the string
107
+        //convert them to doubles
108
+        //perform the operation
109
+        //convert to string
110
+        //return string
75 111
         return null;
76 112
     }
77 113
     
114
+    public static String Subtract(String userInput)
115
+    {
116
+        //take in a string
117
+        //take the numbers out of the string
118
+        //convert them to doubles
119
+        //perform the operation
120
+        //convert to string
121
+        //return string
122
+        return null;
123
+    }
124
+ 
78 125
     public static String InvertSign(String userInput)
79 126
     {
80
-        
127
+        //take in a string
128
+        //take the numbers out of the string
129
+        //convert them to doubles
130
+        //perform the operation
131
+        //convert to string
132
+        //return string
133
+        return null;
134
+    }  
135
+    
136
+    public static String InvertNumber(String userInput)
137
+    {
138
+        //take in a string
139
+        //take the numbers out of the string
140
+        //convert them to doubles
141
+        //perform the operation
142
+        //convert to string
143
+        //return string
144
+        return null;
145
+    } 
146
+
147
+    public static void Clear()
148
+    {
149
+        //take in a string
150
+        //take the numbers out of the string
151
+        //convert them to doubles
152
+        //perform the operation
153
+        //convert to string
154
+        //return string
81 155
     }
82
-   
83 156
 }

+ 20
- 4
MainApplication.java Прегледај датотеку

@@ -1,10 +1,12 @@
1
- 
1
+import java.util.Scanner;
2 2
 
3
-/**
4
- * Created by leon on 2/9/18.
5
- */
6 3
 public class MainApplication {
4
+    boolean on = false;
5
+    Calculations calculator = new Calculations();
6
+    Console console = calculator.console;
7
+    
7 8
     public static void main(String[] args) {
9
+        
8 10
         //Console.println("Welcome to my calculator!");
9 11
         //String s = Console.getStringInput("Enter a string");
10 12
         //Integer i = Console.getIntegerInput("Enter an integer");
@@ -14,4 +16,18 @@ public class MainApplication {
14 16
         //Console.println("The user input %s as a integer", i);
15 17
         //Console.println("The user input %s as a d", d);
16 18
     }
19
+    
20
+    public void Run(){
21
+        Scanner scanner = new Scanner(System.in);       
22
+        while(this.on == true)
23
+        {
24
+            String userInput = scanner.nextLine();
25
+            calculator.getCommand(userInput); 
26
+        }
27
+    }
28
+    
29
+    public void Power(){
30
+        this.on = !this.on;
31
+        this.Run();
32
+    }
17 33
 }

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

@@ -1,5 +1,6 @@
1 1
 #BlueJ package file
2 2
 <<<<<<< HEAD
3
+<<<<<<< HEAD
3 4
 editor.fx.0.height=709
4 5
 editor.fx.0.width=800
5 6
 editor.fx.0.x=480
@@ -21,6 +22,12 @@ editor.fx.0.height=0
21 22
 editor.fx.0.width=0
22 23
 editor.fx.0.x=0
23 24
 editor.fx.0.y=0
25
+=======
26
+editor.fx.0.height=717
27
+editor.fx.0.width=800
28
+editor.fx.0.x=240
29
+editor.fx.0.y=23
30
+>>>>>>> eac4369901be64afb2073e5d3077b9a43303c3c0
24 31
 objectbench.height=200
25 32
 objectbench.width=595
26 33
 package.divider.horizontal=0.6