Procházet zdrojové kódy

Merge branch 'master' of WJB3003/ZCW-MacroLabs-OOP-ScientificCalculator into master

William Brown před 6 roky
rodič
revize
17d3f82bd1
6 změnil soubory, kde provedl 231 přidání a 39 odebrání
  1. 75
    7
      Console.java
  2. 52
    0
      ConsoleTest.java
  3. 4
    10
      MainApplication.java
  4. 21
    0
      opSwitch.java
  5. 56
    22
      package.bluej
  6. 23
    0
      simpleOp.java

+ 75
- 7
Console.java Zobrazit soubor

@@ -1,7 +1,5 @@
1
- 
2
-
3
-import java.util.Scanner;
4
-
1
+import java.util.*;
2
+import java.lang.*;
5 3
 /**
6 4
  * Created by leon on 2/9/18.
7 5
  */
@@ -14,7 +12,7 @@ public class Console {
14 12
     public static void println(String output, Object... args) {
15 13
         print(output + "\n", args);
16 14
     }
17
-
15
+    
18 16
     public static String getStringInput(String prompt) {
19 17
         Scanner scanner = new Scanner(System.in);
20 18
         println(prompt);
@@ -23,10 +21,80 @@ public class Console {
23 21
     }
24 22
 
25 23
     public static Integer getIntegerInput(String prompt) {
26
-        return null;
24
+        Scanner scanner = new Scanner(System.in);
25
+        println(prompt);
26
+        int userInput = scanner.nextInt();
27
+        return userInput;
27 28
     }
28 29
 
29 30
     public static Double getDoubleInput(String prompt) {
30
-        return null;
31
+        Scanner scanner = new Scanner(System.in);
32
+        println(prompt);
33
+        double userInput = scanner.nextDouble();
34
+        return userInput;
35
+    }
36
+
37
+    public static String display(){
38
+        //ALWAYS DISPLAY WHATS IN YOUR CALCULATOR ( STRINGBUILDER )
39
+            return null;
40
+            //return display;
41
+    }
42
+    
43
+    public static void clear(){
44
+        //CLEARS SCREEN / SET TO ZERO ??
45
+    }
46
+    
47
+    public static int getInput(String numberString){
48
+        //GETS INPUT FROM PERSON ( X )
49
+            //String numberString = getStringInput("Please choose a number.");
50
+            quit(numberString);
51
+        try{
52
+            int number1 = Integer.parseInt(numberString);
53
+            System.out.println(number1);
54
+            return number1;
55
+        }catch(Exception e){
56
+            return getInput(numberString);
57
+        }
58
+    }
59
+    /*
60
+    public static int invert(int number){
61
+        //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
62
+        try{
63
+            int invertedNumber = -number;
64
+            System.out.println(invertedNumber);
65
+            return invertedNumber;
66
+        } catch(Exception e){
67
+            return getInput();
68
+        }
69
+    }
70
+    */
71
+    public static int getNumber(String numberString){
72
+        //GETS INPUT FROM PERSON ( Y )
73
+            //System.out.println(first + " " + op);
74
+            //String numberString = getStringInput("Please choose a number.");
75
+            quit(numberString);
76
+        try{
77
+            int number2 = Integer.parseInt(numberString);
78
+            System.out.println(number2);
79
+            return number2;
80
+        }catch(Exception e){
81
+            return getNumber(numberString);
82
+        }
83
+    }
84
+    
85
+    public static String getOp(){
86
+        //GET OPERATION FROM PERSON
87
+            String operation = getStringInput("Please choose your operation.");
88
+            quit(operation);
89
+            opSwitch.choose(operation);
90
+            //return opSwitch.choose(operation1);
91
+            return operation;
92
+    }
93
+    
94
+    public static void quit(String answer){
95
+        if(answer.equals("quit") || answer.equals("exit")){
96
+               System.exit(0);
97
+        }
31 98
     }
99
+   
32 100
 }

+ 52
- 0
ConsoleTest.java Zobrazit soubor

@@ -0,0 +1,52 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class ConsoleTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class ConsoleTest
15
+{
16
+    /**
17
+     * Default constructor for test class ConsoleTest
18
+     */
19
+    public ConsoleTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+
44
+    @Test
45
+    public void getStringInputTest()
46
+    {
47
+        assertEquals("This is a string", Console.getStringInput("Please enter a string"));
48
+    }
49
+}
50
+
51
+
52
+

+ 4
- 10
MainApplication.java Zobrazit soubor

@@ -1,17 +1,11 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by leon on 2/9/18.
5 4
  */
6 5
 public class MainApplication {
7 6
     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.");
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);
7
+        while(true){
8
+            Console.getOp();
9
+        }
16 10
     }
17
-}
11
+}

+ 21
- 0
opSwitch.java Zobrazit soubor

@@ -0,0 +1,21 @@
1
+
2
+/**
3
+ * Write a description of class opSwitch here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class opSwitch
9
+{
10
+    public static void choose(String opInput){
11
+        //if/else state
12
+        if(opInput.equals("add") || opInput.equals("+")){
13
+            String addRequest1 = Console.getStringInput("Whats the first number you'll like to add?");
14
+            String addRequest2 = Console.getStringInput("Whats the second number you'll like to add?");
15
+            simpleOp.add(Console.getInput(addRequest1), Console.getNumber(addRequest2));
16
+        }else if(opInput.equals("invert")){
17
+            String invertRequest = Console.getStringInput("What number would you like to invert?");
18
+            simpleOp.invert(Console.getInput(invertRequest));
19
+        }
20
+    }
21
+}

+ 56
- 22
package.bluej Zobrazit soubor

@@ -1,23 +1,35 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainApplication
2
+dependency1.from=ConsoleTest
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=640
5
+dependency2.from=MainApplication
6
+dependency2.to=Console
7
+dependency2.type=UsesDependency
8
+dependency3.from=Console
9
+dependency3.to=opSwitch
10
+dependency3.type=UsesDependency
11
+dependency4.from=opSwitch
12
+dependency4.to=Console
13
+dependency4.type=UsesDependency
14
+dependency5.from=opSwitch
15
+dependency5.to=simpleOp
16
+dependency5.type=UsesDependency
17
+editor.fx.0.height=711
18
+editor.fx.0.width=811
19
+editor.fx.0.x=469
8 20
 editor.fx.0.y=23
9
-objectbench.height=214
10
-objectbench.width=595
21
+objectbench.height=199
22
+objectbench.width=444
11 23
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
14
-package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
18
-package.frame.width=619
19
-package.numDependencies=1
20
-package.numTargets=2
24
+package.divider.vertical=0.6845329249617151
25
+package.editor.height=440
26
+package.editor.width=342
27
+package.editor.x=0
28
+package.editor.y=23
29
+package.frame.height=711
30
+package.frame.width=468
31
+package.numDependencies=5
32
+package.numTargets=5
21 33
 package.showExtends=true
22 34
 package.showUses=true
23 35
 project.charset=UTF-8
@@ -27,16 +39,38 @@ readme.width=47
27 39
 readme.x=10
28 40
 readme.y=10
29 41
 target1.height=50
30
-target1.name=Console
42
+target1.name=simpleOp
31 43
 target1.showInterface=false
32 44
 target1.type=ClassTarget
33 45
 target1.width=80
34
-target1.x=80
35
-target1.y=200
46
+target1.x=130
47
+target1.y=220
48
+target2.association=ConsoleTest
36 49
 target2.height=50
37
-target2.name=MainApplication
50
+target2.name=Console
38 51
 target2.showInterface=false
39 52
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
53
+target2.width=80
54
+target2.x=130
55
+target2.y=100
56
+target3.height=50
57
+target3.name=opSwitch
58
+target3.showInterface=false
59
+target3.type=ClassTarget
60
+target3.width=80
61
+target3.x=40
62
+target3.y=160
63
+target4.height=50
64
+target4.name=ConsoleTest
65
+target4.showInterface=false
66
+target4.type=UnitTestTargetJunit4
67
+target4.width=80
68
+target4.x=160
69
+target4.y=70
70
+target5.height=50
71
+target5.name=MainApplication
72
+target5.showInterface=false
73
+target5.type=ClassTarget
74
+target5.width=120
75
+target5.x=120
76
+target5.y=10

+ 23
- 0
simpleOp.java Zobrazit soubor

@@ -0,0 +1,23 @@
1
+
2
+/**
3
+ * Write a description of class simpleOp here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class simpleOp
9
+{
10
+    public static int add(int num1, int num2){
11
+        //CALULATES THE SUM OF TWO NUMBERS
12
+        int num3 = num1 + num2;
13
+        System.out.println(num1 + " + " +num2 + " = " + num3);
14
+        return num3;
15
+    }
16
+    
17
+    public static int invert(int number){
18
+        //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
19
+            int invertedNumber = -number;
20
+            System.out.println(invertedNumber);
21
+            return invertedNumber;
22
+    }
23
+}