Sfoglia il codice sorgente

fixed merging conflict

Trinh Tong 6 anni fa
parent
commit
90ad91b48d
3 ha cambiato i file con 207 aggiunte e 129 eliminazioni
  1. 57
    35
      Basic.java
  2. 85
    45
      Trig.java
  3. 65
    49
      package.bluej

+ 57
- 35
Basic.java Vedi File

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

+ 85
- 45
Trig.java Vedi File

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

+ 65
- 49
package.bluej Vedi File

@@ -1,54 +1,62 @@
1 1
 #BlueJ package file
2
-dependency1.from=MainMenu
2
+dependency1.from=Trig
3 3
 dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5
-dependency2.from=SwitchDisplay
5
+dependency10.from=MainApplication
6
+dependency10.to=MemoryFunc
7
+dependency10.type=UsesDependency
8
+dependency11.from=MainApplication
9
+dependency11.to=SwitchDisplay
10
+dependency11.type=UsesDependency
11
+dependency12.from=MainApplication
12
+dependency12.to=Console
13
+dependency12.type=UsesDependency
14
+dependency2.from=Basic
6 15
 dependency2.to=Console
7 16
 dependency2.type=UsesDependency
8
-dependency3.from=SciCalc
9
-dependency3.to=Console
17
+dependency3.from=BasicTest
18
+dependency3.to=Basic
10 19
 dependency3.type=UsesDependency
11
-dependency4.from=MainApplication
12
-dependency4.to=MainMenu
20
+dependency4.from=SciCalc
21
+dependency4.to=Console
13 22
 dependency4.type=UsesDependency
14
-dependency5.from=MainApplication
15
-dependency5.to=SciCalc
23
+dependency5.from=MemoryFunc
24
+dependency5.to=Console
16 25
 dependency5.type=UsesDependency
17
-dependency6.from=MainApplication
18
-dependency6.to=MemoryFunc
26
+dependency6.from=SwitchDisplay
27
+dependency6.to=Console
19 28
 dependency6.type=UsesDependency
20
-dependency7.from=MainApplication
21
-dependency7.to=SwitchDisplay
29
+dependency7.from=MainMenu
30
+dependency7.to=Console
22 31
 dependency7.type=UsesDependency
23 32
 dependency8.from=MainApplication
24
-dependency8.to=Console
33
+dependency8.to=MainMenu
25 34
 dependency8.type=UsesDependency
26
-dependency9.from=MemoryFunc
27
-dependency9.to=Console
35
+dependency9.from=MainApplication
36
+dependency9.to=SciCalc
28 37
 dependency9.type=UsesDependency
29
-<<<<<<< HEAD
30 38
 editor.fx.0.height=0
31 39
 editor.fx.0.width=0
32 40
 editor.fx.0.x=0
33 41
 editor.fx.0.y=0
34
-=======
35 42
 editor.fx.0.height=722
36 43
 editor.fx.0.width=1120
37 44
 editor.fx.0.x=320
38 45
 editor.fx.0.y=119
39
->>>>>>> master
46
+=======
47
+>>>>>>> origin
40 48
 objectbench.height=214
41
-objectbench.width=595
49
+objectbench.width=706
42 50
 package.divider.horizontal=0.6
43
-package.divider.vertical=0.6847360912981455
44
-package.editor.height=473
45
-package.editor.width=493
51
+package.divider.vertical=0.720253164556962
52
+package.editor.height=562
53
+package.editor.width=604
46 54
 package.editor.x=35
47
-package.editor.y=59
48
-package.frame.height=759
49
-package.frame.width=619
50
-package.numDependencies=9
51
-package.numTargets=8
55
+package.editor.y=60
56
+package.frame.height=848
57
+package.frame.width=730
58
+package.numDependencies=12
59
+package.numTargets=9
52 60
 package.showExtends=true
53 61
 package.showUses=true
54 62
 project.charset=UTF-8
@@ -57,6 +65,7 @@ readme.name=@README
57 65
 readme.width=47
58 66
 readme.x=10
59 67
 readme.y=10
68
+target1.association=BasicTest
60 69
 target1.height=50
61 70
 target1.name=Basic
62 71
 target1.showInterface=false
@@ -69,47 +78,54 @@ target2.name=SciCalc
69 78
 target2.showInterface=false
70 79
 target2.type=ClassTarget
71 80
 target2.width=80
72
-target2.x=10
73
-target2.y=280
81
+target2.x=120
82
+target2.y=10
74 83
 target3.height=50
75 84
 target3.name=MemoryFunc
76 85
 target3.showInterface=false
77 86
 target3.type=ClassTarget
78 87
 target3.width=110
79
-target3.x=210
80
-target3.y=350
88
+target3.x=10
89
+target3.y=130
81 90
 target4.height=50
82 91
 target4.name=Console
83 92
 target4.showInterface=false
84 93
 target4.type=ClassTarget
85 94
 target4.width=80
86
-target4.x=70
87
-target4.y=170
95
+target4.x=80
96
+target4.y=200
88 97
 target5.height=50
89
-target5.name=Trig
98
+target5.name=BasicTest
90 99
 target5.showInterface=false
91
-target5.type=ClassTarget
100
+target5.type=UnitTestTargetJunit4
92 101
 target5.width=80
93
-target5.x=320
94
-target5.y=70
102
+target5.x=350
103
+target5.y=150
95 104
 target6.height=50
96
-target6.name=SwitchDisplay
105
+target6.name=Trig
97 106
 target6.showInterface=false
98 107
 target6.type=ClassTarget
99
-target6.width=110
100
-target6.x=80
101
-target6.y=350
108
+target6.width=80
109
+target6.x=320
110
+target6.y=70
102 111
 target7.height=50
103
-target7.name=MainMenu
112
+target7.name=SwitchDisplay
104 113
 target7.showInterface=false
105 114
 target7.type=ClassTarget
106
-target7.width=90
107
-target7.x=70
108
-target7.y=10
115
+target7.width=110
116
+target7.x=120
117
+target7.y=130
109 118
 target8.height=50
110
-target8.name=MainApplication
119
+target8.name=MainMenu
111 120
 target8.showInterface=false
112 121
 target8.type=ClassTarget
113
-target8.width=120
114
-target8.x=70
115
-target8.y=70
122
+target8.width=90
123
+target8.x=170
124
+target8.y=190
125
+target9.height=50
126
+target9.name=MainApplication
127
+target9.showInterface=false
128
+target9.type=ClassTarget
129
+target9.width=120
130
+target9.x=70
131
+target9.y=70