Kate Moore 6 лет назад
Родитель
Сommit
c97b4410fb
6 измененных файлов: 224 добавлений и 68 удалений
  1. 14
    5
      Console.java
  2. 11
    12
      MainApplication.java
  3. 33
    0
      Operations.java
  4. 129
    29
      calculator.java
  5. 8
    0
      calculatorTest.java
  6. 29
    22
      package.bluej

+ 14
- 5
Console.java Просмотреть файл

@@ -1,7 +1,5 @@
1
- 
2 1
 
3 2
 import java.util.Scanner;
4
-
5 3
 /**
6 4
  * Created by leon on 2/9/18.
7 5
  */
@@ -9,8 +7,9 @@ public class Console {
9 7
 
10 8
     public static void print(String output, Object... args) {
11 9
         System.out.printf(output, args);
12
-    }
13 10
 
11
+    }
12
+    
14 13
     public static void println(String output, Object... args) {
15 14
         print(output + "\n", args);
16 15
     }
@@ -21,12 +20,22 @@ public class Console {
21 20
         String userInput = scanner.nextLine();
22 21
         return userInput;
23 22
     }
24
-
23
+    
24
+    public static Double getDoubleInput(String prompt) {
25
+        Scanner scanner = new Scanner(System.in);
26
+        println(prompt);
27
+        String userInput = scanner.nextLine();
28
+        return userInput.parseDouble();
29
+    }
30
+    
25 31
     public static Integer getIntegerInput(String prompt) {
26 32
         return null;
27 33
     }
28 34
 
29 35
     public static Double getDoubleInput(String prompt) {
30
-        return null;
36
+        Scanner sc = new Scanner(System.in);
37
+        Double userNumber1 = sc.nextDouble();
38
+        return userNumber1;
39
+        
31 40
     }
32 41
 }

+ 11
- 12
MainApplication.java Просмотреть файл

@@ -1,17 +1,16 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by leon on 2/9/18.
5 4
  */
6
-public class MainApplication {
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.");
5
+// public class MainApplication {
6
+    // public static void main(String[] args) {
7
+        // Console.println("Welcome to my calculator!");
8
+        // String s = Console.getStringInput("Enter a string");
9
+        // Integer i = Console.getIntegerInput("Enter an integer");
10
+        // Double d = Console.getDoubleInput("Enter a double.");
12 11
 
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
-    }
17
-}
12
+        // Console.println("The user input %s as a string", s);
13
+        // Console.println("The user input %s as a integer", i);
14
+        // Console.println("The user input %s as a d", d);
15
+    // }
16
+// }

+ 33
- 0
Operations.java Просмотреть файл

@@ -0,0 +1,33 @@
1
+import java.util.*;
2
+
3
+public class Operations
4
+{
5
+    // instance variables - replace the example below with your own
6
+    private int x;
7
+
8
+    /**
9
+     * Constructor for objects of class Operations
10
+     */
11
+    public Operations()
12
+    {
13
+        // initialise instance variables
14
+        x = 0;
15
+    }
16
+
17
+    /**
18
+     * An example of a method - replace this comment with your own
19
+     *
20
+     * @param  y  a sample parameter for a method
21
+     * @return    the sum of x and y
22
+     */
23
+    public int factorial(int number)
24
+    {
25
+        int fact = 1;
26
+          for(int i = 1; i <= number; i++) {
27
+              fact *= i;
28
+          }
29
+          return fact;
30
+    }
31
+    
32
+    public int 
33
+}

+ 129
- 29
calculator.java Просмотреть файл

@@ -1,33 +1,133 @@
1
+import java.util.*;
1 2
 
2
-/**
3
- * Write a description of class calculator here.
4
- *
5
- * @author (your name)
6
- * @version (a version number or a date)
7
- */
8
-public class calculator
9
-{
10
-    // instance variables - replace the example below with your own
11
-    private int x;
12
-
13
-    /**
14
-     * Constructor for objects of class calculator
15
-     */
16
-    public calculator()
17
-    {
18
-        // initialise instance variables
19
-        x = 0;
20
-    }
21 3
 
22
-    /**
23
-     * An example of a method - replace this comment with your own
24
-     *
25
-     * @param  y  a sample parameter for a method
26
-     * @return    the sum of x and y
27
-     */
28
-    public int add(int y)
29
-    {
30
-        // put your code here
31
-        return x + y;
4
+public class Calculator {
5
+
6
+
7
+  public static void main(String[] args) {
8
+
9
+    double displayNum = 0;
10
+    boolean calcOn = true;
11
+    double num;
12
+
13
+    Scanner sc = new Scanner(System.in);
14
+
15
+    while (calcOn) {
16
+
17
+      System.out.println(displayNum);
18
+      
19
+      System.out.println("Enter an option:  ");
20
+      System.out.println("0 - ENTER NUMBER");
21
+      System.out.println("1 - ADD ");
22
+      System.out.println("2 - SUBTRACT");
23
+      System.out.println("3 - MULTIPLY");
24
+      System.out.println("4 - DIVIDE");
25
+      System.out.println("5 - SQUARE");
26
+      System.out.println("6 - SQUARE ROOT");
27
+      System.out.println("7 - EXPONENT");
28
+      System.out.println("8 - Invert +/-");
29
+      System.out.println("9 - INVERSE");
30
+      System.out.println("10 - SIN");
31
+      System.out.println("11 - COS");
32
+      System.out.println("12 - TAN");
33
+      System.out.println("13 - INVERSE SIN");
34
+      System.out.println("14 - INVERSE COS");
35
+      System.out.println("15 - INVERSE TAN");
36
+      System.out.println("16 - QUIT");
37
+      
38
+      
39
+
40
+
41
+      int userInput = sc.nextInt();
42
+      //displayNum = userInput;
43
+      System.out.println(displayNum);
44
+      
45
+      switch(userInput) {
46
+        case 0: System.out.println("enter number");
47
+                num = sc.nextDouble();
48
+                displayNum = num;
49
+                break;
50
+        case 1: System.out.println("enter number to ADD to " + displayNum);
51
+                num = sc.nextDouble();
52
+                displayNum = num + displayNum;
53
+                break;
54
+        case 2: System.out.println("enter number to SUBTRACT from " + displayNum);
55
+                num = sc.nextDouble();
56
+                displayNum = displayNum - num;
57
+                break;
58
+        case 3: System.out.println("enter number to MULTIPLY to" + displayNum);
59
+                num = sc.nextDouble();
60
+                displayNum = num * displayNum;
61
+                break;
62
+         case 4: System.out.println("enter number to DIVIDE from " + displayNum);
63
+                num = sc.nextDouble();
64
+                displayNum = displayNum / num;
65
+                break;
66
+         case 5: System.out.println("square result: " + displayNum * displayNum);
67
+                num = sc.nextDouble();
68
+               // displayNum = displayNum * displayNum;
69
+                break;
70
+         case 6: System.out.println("square root result: " + Math.sqrt(displayNum));
71
+                num = sc.nextDouble();
72
+                break;
73
+         case 7: System.out.println("enter an exponent to the number: " + displayNum);
74
+                num = sc.nextDouble();
75
+                displayNum = Math.pow(displayNum, num);
76
+                break;
77
+         case 8: System.out.println("result: " + displayNum * -1);
78
+                num = sc.nextDouble();
79
+                break;
80
+         case 9: System.out.println("result: " + Math.sqrt(displayNum));
81
+                num = sc.nextDouble();
82
+               // displayNum = displayNum * displayNum;
83
+                break;
84
+         case 10: System.out.println("result: " + Math.sin(displayNum));
85
+                num = sc.nextDouble();
86
+               // displayNum = displayNum * displayNum;
87
+                break;
88
+         case 11: System.out.println("result: " + Math.cos(displayNum));
89
+                num = sc.nextDouble();
90
+               // displayNum = displayNum * displayNum;
91
+                break;
92
+         case 12: System.out.println("result: " + Math.tan(displayNum));
93
+                num = sc.nextDouble();
94
+               // displayNum = displayNum * displayNum;
95
+                break;
96
+         case 13: System.out.println("result: " + Math.asin(displayNum));
97
+                num = sc.nextDouble();
98
+               // displayNum = displayNum * displayNum;
99
+                break;
100
+         case 14: System.out.println("result: " + Math.acos(displayNum));
101
+                num = sc.nextDouble();
102
+               // displayNum = displayNum * displayNum;
103
+                break;
104
+         case 15: System.out.println("result: " + Math.atan(displayNum));
105
+                num = sc.nextDouble();
106
+               // displayNum = displayNum * displayNum;
107
+                break;
108
+         case 16: System.out.println("Quitting!");
109
+                calcOn = false;
110
+                break;
111
+         default: break;
112
+                
113
+        } 
114
+
32 115
     }
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+  }
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
33 133
 }

+ 8
- 0
calculatorTest.java Просмотреть файл

@@ -39,4 +39,12 @@ public class calculatorTest
39 39
     public void tearDown()
40 40
     {
41 41
     }
42
+
43
+    @Test
44
+    public void TestAdd()
45
+    {
46
+        //calculator calculat1 = new calculator();
47
+        //assertEquals(10, calculat1.add(5, 5));
48
+    }
42 49
 }
50
+

+ 29
- 22
package.bluej Просмотреть файл

@@ -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=480
8
-editor.fx.0.y=23
9
-objectbench.height=205
5
+editor.fx.0.height=0
6
+editor.fx.0.width=0
7
+editor.fx.0.x=0
8
+editor.fx.0.y=0
9
+objectbench.height=201
10 10
 objectbench.width=595
11 11
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6845238095238095
13
-package.editor.height=453
12
+package.divider.vertical=0.6804915514592934
13
+package.editor.height=436
14 14
 package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=23
17
-package.frame.height=730
15
+package.editor.x=89
16
+package.editor.y=38
17
+package.frame.height=709
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=4
20
+package.numTargets=5
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -28,10 +28,10 @@ readme.x=10
28 28
 readme.y=10
29 29
 target1.association=calculatorTest
30 30
 target1.height=50
31
-target1.name=calculator
31
+target1.name=Calculator
32 32
 target1.showInterface=false
33 33
 target1.type=ClassTarget
34
-target1.width=90
34
+target1.width=130
35 35
 target1.x=70
36 36
 target1.y=10
37 37
 target2.height=50
@@ -42,16 +42,23 @@ target2.width=80
42 42
 target2.x=80
43 43
 target2.y=200
44 44
 target3.height=50
45
-target3.name=calculatorTest
45
+target3.name=Operations
46 46
 target3.showInterface=false
47
-target3.type=UnitTestTargetJunit4
47
+target3.type=ClassTarget
48 48
 target3.width=90
49
-target3.x=100
50
-target3.y=-20
49
+target3.x=10
50
+target3.y=130
51 51
 target4.height=50
52
-target4.name=MainApplication
52
+target4.name=calculatorTest
53 53
 target4.showInterface=false
54
-target4.type=ClassTarget
55
-target4.width=120
56
-target4.x=70
57
-target4.y=70
54
+target4.type=UnitTestTargetJunit4
55
+target4.width=130
56
+target4.x=100
57
+target4.y=-20
58
+target5.height=50
59
+target5.name=MainApplication
60
+target5.showInterface=false
61
+target5.type=ClassTarget
62
+target5.width=120
63
+target5.x=70
64
+target5.y=70