Explorar el Código

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

trtong hace 6 años
padre
commit
c3f98976f9
Se han modificado 3 ficheros con 120 adiciones y 62 borrados
  1. 51
    25
      Basic.java
  2. 59
    27
      Trig.java
  3. 10
    10
      package.bluej

+ 51
- 25
Basic.java Ver fichero

@@ -1,4 +1,4 @@
1
-import java.util.Scanner;
1
+
2 2
 
3 3
 /**
4 4
  * Basic class to perform basic functions for our Graphing Calculator
@@ -10,56 +10,82 @@ public class Basic
10 10
 {
11 11
     int input1 = 0;
12 12
     int input2 = 0;
13
+    String operation = "";
13 14
     int answer;
14 15
     
15 16
     public Basic()
16 17
     {
18
+        //a check to make sure user input is valid.
17 19
         boolean validInput = false;
18 20
         
19 21
         while(!validInput) {
20 22
         //Get input of first number
21
-        Scanner in2 = new Scanner(System.in);
22
-        System.out.println("What is the first number?");
23
-        input1 = in2.nextInt();
23
+        input1 = Console.getIntegerInput("What is the first number?");
24 24
             
25
-        //Get input of type of function
26
-        Scanner in1 = new Scanner(System.in);
27
-        System.out.println("Which operation would you like to perform? \n +, -, *, /");
28
-        String operation = in1.nextLine(); 
25
+        //Get input of operation
26
+        operation = Console.getStringInput("Which operation would you like to perform? \n +, -, *, /");
29 27
   
30 28
         //Get input of second number
31
-        Scanner in3 = new Scanner(System.in);
32
-        System.out.println("What is the second number?");
33
-        input2 = in3.nextInt();
29
+        input2 = Console.getIntegerInput("What is the second number?");
34 30
         
35
-        //Do the math depending on the input.
31
+        //Do the math depending on the inputs.
32
+        //addition
36 33
         if (operation.equals("+")) {
37
-            answer = input1 + input2;
38
-            System.out.println(answer);
34
+            getSum(input1, input2);
39 35
             validInput = true;
40
-            
36
+        
37
+        //subtraction    
41 38
         } else if (operation.equals("-")) {
42
-            answer = input1 - input2;
43
-            System.out.println(answer);
39
+            getDiff(input1, input2);
44 40
             validInput = true;
45
-            
41
+        
42
+        //multiplication
46 43
         } else if (operation.equals("*")) {
47
-            answer = input1 * input2;
48
-            System.out.println(answer);
44
+            getProduct(input1, input2);
49 45
             validInput = true;
50 46
             
47
+        //division    
51 48
         } else if (operation.equals("/")) {
52
-            answer = input1 / input2;
53
-            System.out.println(answer);
49
+            //error message when trying to divide by 0.
50
+            if (input2 == 0) {
51
+                Console.println("undefined");
52
+                //Insert return to main menu.
53
+            } else {
54
+            getQuotient(input1, input2);
54 55
             validInput = true;
55
-            
56
+        }
56 57
         } else {
57
-            System.out.println("Error, try again \n");
58
+            //error if wrong input was entered
59
+            Console.println("Error, try again \n");
58 60
             
59 61
     }
62
+    
60 63
 }
61
-    //Insert return to main menu.
64
+         //Insert return to main menu.
62 65
 }
66
+    //addition method
67
+    public void getSum(int x, int y) {
68
+        answer = x + y;
69
+        Console.println(Double.toString(answer));
70
+    }
71
+    
72
+    //subtraction method
73
+    public void getDiff(int x, int y) {
74
+        answer = x - y;
75
+        Console.println(Double.toString(answer));
76
+    }
77
+    
78
+    //multiplication method
79
+    public void getProduct(int x, int y) {
80
+        answer = x * y;
81
+        Console.println(Double.toString(answer));
82
+    }
83
+    
84
+    //division method
85
+    public void getQuotient(int x, int y) {
86
+        answer = x / y;
87
+        Console.println(Double.toString(answer));
88
+    }
63 89
 }
64 90
 
65 91
         

+ 59
- 27
Trig.java Ver fichero

@@ -1,5 +1,4 @@
1 1
 
2
-import java.util.Scanner;
3 2
 
4 3
 /**
5 4
  * Trig class to perform trig function for our Graphing Calculator
@@ -11,76 +10,109 @@ public class Trig
11 10
 {
12 11
     int input = 0;
13 12
     double answer;
13
+    String operation = "";
14 14
     
15 15
     public Trig()
16 16
     {
17
+        //a check to make sure user input is valid
17 18
         boolean validInput = false;
18 19
         
19 20
         while(!validInput) {
20 21
         //Get input of type of function
21
-        Scanner in1 = new Scanner(System.in);
22
-        System.out.println("Which trignometric function would you like to run? \n sin, cos, tan, arcsin, arccos, arctan");
23
-        String operation = in1.nextLine(); 
22
+        operation = Console.getStringInput("Which trignometric function would you like to run? \n sin, cos, tan, arcsin, arccos, arctan");
24 23
         operation = operation.toLowerCase();
25 24
         
26 25
         //Get input of number
27
-        Scanner in2 = new Scanner(System.in);
28
-        System.out.println("What number would you like to find the " + operation + " of?");
29
-        int input = in2.nextInt();
26
+        input = Console.getIntegerInput("What number would you like to find the " + operation + " of?");
30 27
         
31 28
         //Do the math depending on the input.
29
+        //SIN
32 30
         if (operation.equals("sin")) {
33
-            answer = Math.sin(input);
34
-            System.out.println(answer);
31
+            calcSin(input);
35 32
             validInput = true;
36 33
             
34
+        //COS
37 35
         } else if (operation.equals("cos")) {
38
-            answer = Math.cos(input);
39
-            System.out.println(answer);
36
+            calcCos(input);
40 37
             validInput = true;
41 38
             
39
+        //TAN
42 40
         } else if (operation.equals("tan")) {
43
-            answer = Math.tan(input);
44
-            System.out.println(answer);
41
+            calcTan(input);
45 42
             validInput = true;
46 43
             
44
+        //ARCSIN
47 45
         } else if (operation.equals("arcsin")) {
48
-            answer = Math.asin(input);
49
-            System.out.println(answer);
46
+            calcArcsin(input);
50 47
             validInput = true;
51 48
             
49
+        //ARCCOS
52 50
         } else if (operation.equals("arccos")) {
53
-            answer = Math.acos(input);
54
-            System.out.println(answer);
51
+            calcArccos(input);
55 52
             validInput = true;
56 53
             
54
+        //ARCTAN
57 55
         } else if (operation.equals("arctan")) {
58
-            answer = Math.atan(input);
59
-            System.out.println(answer);
56
+            calcArctan(input);
60 57
             validInput = true;
61
-            
58
+           
59
+        //Error message if input does not match options, loops back to the top so they can try again.
62 60
         } else {
63
-            System.out.println("Error, try again \n");
61
+            Console.println("Error, try again \n");
64 62
             
65 63
     }
66 64
 }
67 65
         //Ask if they would like to convert.
68
-        System.out.println("Would you like to convert your answer from radian to degrees?  Y or N");
69
-        Scanner in3 = new Scanner(System.in);
70
-        String response = in3.nextLine();
66
+        String response = Console.getStringInput("Would you like to convert your answer from radian to degrees?  Y or N");
71 67
         response = response.toLowerCase();
72 68
         if (response.equals("y")) {
73 69
             toDegrees(answer);
74 70
     } else {
75
-        System.out.println("Have a nice day!");
71
+        Console.println("Have a nice day!");
76 72
         //Insert Return to Main Menu
77 73
 }
78 74
     }
79
-
75
+    //Sin method
76
+    public void calcSin(int x) {
77
+        answer = Math.sin(x);
78
+        Console.println(Double.toString(answer));
79
+    }
80
+    
81
+    //Cos method
82
+    public void calcCos(int x) {
83
+        answer = Math.cos(x);
84
+        Console.println(Double.toString(answer));
85
+    }
86
+    
87
+    //Tan method
88
+    public void calcTan(int x) {
89
+        answer = Math.tan(x);
90
+        Console.println(Double.toString(answer));
91
+    }
92
+    
93
+    //Arcsin method
94
+    public void calcArcsin(int x) {
95
+        answer = Math.asin(x);
96
+        Console.println(Double.toString(answer));
97
+    }
98
+    
99
+    //Arccos method
100
+    public void calcArccos(int x) {
101
+        answer = Math.acos(x);
102
+        Console.println(Double.toString(answer));
103
+    }
104
+    
105
+    //Arctan method
106
+    public void calcArctan(int x) {
107
+        answer = Math.atan(x);
108
+        Console.println(Double.toString(answer));
109
+    }
110
+    
111
+    //Converting from Radians to Degrees
80 112
     public void toDegrees(double answer) 
81 113
     {
82 114
         double conversion = Math.toDegrees(answer);
83
-        System.out.println(conversion);
115
+        Console.println(Double.toString(conversion));
84 116
         //Insert Return to Main Menu
85 117
     }
86 118
 }

+ 10
- 10
package.bluej Ver fichero

@@ -45,13 +45,13 @@ editor.fx.0.height=722
45 45
 editor.fx.0.width=1120
46 46
 editor.fx.0.x=320
47 47
 editor.fx.0.y=119
48
->>>>>>> trinhsCalc
48
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
49 49
 objectbench.height=214
50
-objectbench.width=595
50
+objectbench.width=706
51 51
 package.divider.horizontal=0.6
52
-package.divider.vertical=0.6847360912981455
53
-package.editor.height=473
54
-package.editor.width=493
52
+package.divider.vertical=0.720253164556962
53
+package.editor.height=562
54
+package.editor.width=604
55 55
 package.editor.x=35
56 56
 package.editor.y=59
57 57
 package.frame.height=759
@@ -60,8 +60,8 @@ package.frame.width=619
60 60
 package.numDependencies=4
61 61
 =======
62 62
 package.numDependencies=9
63
->>>>>>> trinhsCalc
64 63
 package.numTargets=8
64
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
65 65
 package.showExtends=true
66 66
 package.showUses=true
67 67
 project.charset=UTF-8
@@ -71,12 +71,12 @@ readme.width=47
71 71
 readme.x=10
72 72
 readme.y=10
73 73
 target1.height=50
74
-target1.name=Basic
74
+target1.name=AdvCalc
75 75
 target1.showInterface=false
76 76
 target1.type=ClassTarget
77 77
 target1.width=80
78
-target1.x=320
79
-target1.y=180
78
+target1.x=90
79
+target1.y=10
80 80
 target2.height=50
81 81
 target2.name=SciCalc
82 82
 target2.showInterface=false
@@ -95,7 +95,7 @@ target3.y=410
95 95
 =======
96 96
 target3.x=210
97 97
 target3.y=350
98
->>>>>>> trinhsCalc
98
+>>>>>>> 5b0bd69a84477726debf8e0b897ce7f6e0cbe025
99 99
 target4.height=50
100 100
 target4.name=Console
101 101
 target4.showInterface=false