Ver código fonte

updated methods with return statements

Lauren Green 6 anos atrás
pai
commit
0ab5b28c57
3 arquivos alterados com 128 adições e 132 exclusões
  1. 19
    23
      Basic.java
  2. 44
    36
      Trig.java
  3. 65
    73
      package.bluej

+ 19
- 23
Basic.java Ver arquivo

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

+ 44
- 36
Trig.java Ver arquivo

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

+ 65
- 73
package.bluej Ver arquivo

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