#35 Steffon Williams

Aperto
Stwillia94 vorrebbe unire 1 commit da Stwillia94/ZCW-MacroLabs-OOP-ScientificCalculator:master a master
6 ha cambiato i file con 218 aggiunte e 45 eliminazioni
  1. 67
    27
      Console.java
  2. 48
    0
      ConsoleTest.java
  3. 2
    2
      MainApplication.java
  4. 42
    0
      MainApplicationTest.java
  5. 20
    0
      operator.java
  6. 39
    16
      package.bluej

+ 67
- 27
Console.java Vedi File

@@ -1,32 +1,72 @@
1
- 
2
-
3
-import java.util.Scanner;
4
-
1
+import java.lang.Math;
2
+import java.util.*;
5 3
 /**
6 4
  * Created by leon on 2/9/18.
7 5
  */
8
-public class Console {
9
-
10
-    public static void print(String output, Object... args) {
11
-        System.out.printf(output, args);
12
-    }
13
-
14
-    public static void println(String output, Object... args) {
15
-        print(output + "\n", args);
16
-    }
17
-
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
-    }
24
-
25
-    public static Integer getIntegerInput(String prompt) {
26
-        return null;
27
-    }
28
-
29
-    public static Double getDoubleInput(String prompt) {
30
-        return null;
6
+public class Console {    
7
+    public static void main(String[] args){
8
+        boolean run = true;                
9
+        double x = 0;
10
+        double y = 0;
11
+        double answer = 0.0;        
12
+        Scanner scanObject = new Scanner(System.in);
13
+   
14
+        while (run) {
15
+                System.out.println("Enter A number: ");
16
+                x = scanObject.nextDouble();
17
+                System.out.println("Enter An operation? Choose one below.");
18
+                System.out.println("( sin ) ( cos ) ( tan ) ( asin ) ( acos ) ( atan ) ( sqrt ) ");
19
+                System.out.println("( + ) ( - ) ( * ) ( / ) ( ^ )");
20
+                String operator = scanObject.next();//.charAt(0);
21
+                String s = "";  
22
+                if (operator.equals("sin") || operator.equals("asin") || operator.equals("cos") || operator.equals("acos") || operator.equals("tan") || operator.equals("atan") || operator.equals("sqrt")) {
23
+                        switch (operator){
24
+                            case "sin": answer = Math.toDegrees(Math.sin(x));
25
+                                break;
26
+                            case "asin": answer = Math.toDegrees(Math.asin(x));
27
+                                break;                    
28
+                            case "cos": answer = Math.toDegrees(Math.cos(x));
29
+                                break;
30
+                            case "acos": answer = Math.toDegrees(Math.acos(x));
31
+                                break;                    
32
+                            case "tan": answer = Math.toDegrees(Math.tan(x));
33
+                                break;
34
+                            case "atan": answer = Math.toDegrees(Math.atan(x));
35
+                                break;
36
+                            case "sqrt": answer = Math.toDegrees(Math.sqrt(x));
37
+                                break;                                
38
+                       //case "!": answer = factorial(x);
39
+                           //break;                                
40
+                        }            
41
+                            System.out.println(Math.toRadians(answer));
42
+                            continue;
43
+               } else                         
44
+                
45
+                   
46
+                System.out.println("Enter A second number: ");
47
+                y = scanObject.nextDouble();
48
+                s = scanObject.nextLine();
49
+            
50
+                switch (operator) {
51
+                       case "+": answer = x + y;
52
+                           break;
53
+                       case "-": answer = x - y;
54
+                           break;
55
+                       case "*": answer = x * y;
56
+                           break;
57
+                       case "/": answer = x/y;
58
+                           break;
59
+                       case "^": answer = Math.pow (x,y);
60
+                           break;
61
+                           
62
+                }        
63
+                   System.out.println(x + " " + operator + " " + y + " = " + answer);
64
+                   System.out.println("Continue or Quit");
65
+                   s = scanObject.nextLine();
66
+                   if (s.equalsIgnoreCase("Quit")){
67
+                       System.out.println("Have A good day!! :) ");
68
+                       break;
69
+                    }
70
+        }
31 71
     }
32 72
 }

+ 48
- 0
ConsoleTest.java Vedi File

@@ -0,0 +1,48 @@
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
+    @Test
44
+    public void Calculator()
45
+    {
46
+    }
47
+}
48
+

+ 2
- 2
MainApplication.java Vedi File

@@ -2,7 +2,7 @@
2 2
 
3 3
 /**
4 4
  * Created by leon on 2/9/18.
5
- */
5
+ 
6 6
 public class MainApplication {
7 7
     public static void main(String[] args) {
8 8
         Console.println("Welcome to my calculator!");
@@ -14,4 +14,4 @@ public class MainApplication {
14 14
         Console.println("The user input %s as a integer", i);
15 15
         Console.println("The user input %s as a d", d);
16 16
     }
17
-}
17
+}*/

+ 42
- 0
MainApplicationTest.java Vedi File

@@ -0,0 +1,42 @@
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 MainApplicationTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class MainApplicationTest
15
+{
16
+    /**
17
+     * Default constructor for test class MainApplicationTest
18
+     */
19
+    public MainApplicationTest()
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
+}

+ 20
- 0
operator.java Vedi File

@@ -0,0 +1,20 @@
1
+
2
+/**
3
+ * Write a description of class operator here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class operator
9
+{
10
+
11
+
12
+
13
+    public operator()
14
+    {
15
+        // initialise instance variables
16
+    
17
+    }
18
+
19
+
20
+}

+ 39
- 16
package.bluej Vedi File

@@ -2,22 +2,22 @@
2 2
 dependency1.from=MainApplication
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
8
-editor.fx.0.y=23
5
+editor.fx.0.height=850
6
+editor.fx.0.width=1142
7
+editor.fx.0.x=568
8
+editor.fx.0.y=-936
9 9
 objectbench.height=214
10 10
 objectbench.width=595
11 11
 package.divider.horizontal=0.6
12 12
 package.divider.vertical=0.6847360912981455
13 13
 package.editor.height=473
14 14
 package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
15
+package.editor.x=-109
16
+package.editor.y=-994
17 17
 package.frame.height=759
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=2
20
+package.numTargets=5
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -27,16 +27,39 @@ readme.width=47
27 27
 readme.x=10
28 28
 readme.y=10
29 29
 target1.height=50
30
-target1.name=Console
30
+target1.name=MainApplicationTest
31 31
 target1.showInterface=false
32
-target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=120
34
+target1.x=110
35
+target1.y=40
36
+target2.association=ConsoleTest
36 37
 target2.height=50
37
-target2.name=MainApplication
38
+target2.name=Console
38 39
 target2.showInterface=false
39 40
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
41
+target2.width=80
42
+target2.x=80
43
+target2.y=200
44
+target3.height=50
45
+target3.name=ConsoleTest
46
+target3.showInterface=false
47
+target3.type=UnitTestTargetJunit4
48
+target3.width=80
49
+target3.x=110
50
+target3.y=170
51
+target4.height=50
52
+target4.name=operator
53
+target4.showInterface=false
54
+target4.type=ClassTarget
55
+target4.width=80
56
+target4.x=240
57
+target4.y=110
58
+target5.association=MainApplicationTest
59
+target5.height=50
60
+target5.name=MainApplication
61
+target5.showInterface=false
62
+target5.type=ClassTarget
63
+target5.width=120
64
+target5.x=80
65
+target5.y=70