Quellcode durchsuchen

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

trtong vor 6 Jahren
Ursprung
Commit
5a1002094e
2 geänderte Dateien mit 100 neuen und 5 gelöschten Zeilen
  1. 88
    0
      Trig.java
  2. 12
    5
      package.bluej

+ 88
- 0
Trig.java Datei anzeigen

@@ -0,0 +1,88 @@
1
+
2
+import java.util.Scanner;
3
+
4
+/**
5
+ * Trig class to perform trig function for our Graphing Calculator
6
+ * (sin, cos, tan, inverses, degree to radian)
7
+ * Lauren Green
8
+ * 10/19/18
9
+ */
10
+public class Trig
11
+{
12
+    int input = 0;
13
+    double answer;
14
+    
15
+    public Trig()
16
+    {
17
+        boolean validInput = false;
18
+        
19
+        while(!validInput) {
20
+        //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(); 
24
+        operation = operation.toLowerCase();
25
+        
26
+        //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();
30
+        
31
+        //Do the math depending on the input.
32
+        if (operation.equals("sin")) {
33
+            answer = Math.sin(input);
34
+            System.out.println(answer);
35
+            validInput = true;
36
+            
37
+        } else if (operation.equals("cos")) {
38
+            answer = Math.cos(input);
39
+            System.out.println(answer);
40
+            validInput = true;
41
+            
42
+        } else if (operation.equals("tan")) {
43
+            answer = Math.tan(input);
44
+            System.out.println(answer);
45
+            validInput = true;
46
+            
47
+        } else if (operation.equals("arcsin")) {
48
+            answer = Math.asin(input);
49
+            System.out.println(answer);
50
+            validInput = true;
51
+            
52
+        } else if (operation.equals("arccos")) {
53
+            answer = Math.acos(input);
54
+            System.out.println(answer);
55
+            validInput = true;
56
+            
57
+        } else if (operation.equals("arctan")) {
58
+            answer = Math.atan(input);
59
+            System.out.println(answer);
60
+            validInput = true;
61
+            
62
+        } else {
63
+            System.out.println("Error, try again \n");
64
+            
65
+    }
66
+}
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
+        ///Return to Main Application
77
+}
78
+    }
79
+
80
+    public void toDegrees(double answer) 
81
+    {
82
+        double conversion = Math.toDegrees(answer);
83
+        System.out.println(conversion);
84
+        ///Return to Main Application
85
+    }
86
+}
87
+
88
+    

+ 12
- 5
package.bluej Datei anzeigen

@@ -4,7 +4,7 @@ dependency1.to=Console
4 4
 dependency1.type=UsesDependency
5 5
 editor.fx.0.height=722
6 6
 editor.fx.0.width=800
7
-editor.fx.0.x=640
7
+editor.fx.0.x=801
8 8
 editor.fx.0.y=23
9 9
 objectbench.height=214
10 10
 objectbench.width=595
@@ -17,7 +17,7 @@ package.editor.y=60
17 17
 package.frame.height=759
18 18
 package.frame.width=619
19 19
 package.numDependencies=1
20
-package.numTargets=2
20
+package.numTargets=3
21 21
 package.showExtends=true
22 22
 package.showUses=true
23 23
 project.charset=UTF-8
@@ -34,9 +34,16 @@ target1.width=80
34 34
 target1.x=80
35 35
 target1.y=200
36 36
 target2.height=50
37
-target2.name=MainApplication
37
+target2.name=Trig
38 38
 target2.showInterface=false
39 39
 target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
40
+target2.width=80
41
+target2.x=320
42 42
 target2.y=70
43
+target3.height=50
44
+target3.name=MainApplication
45
+target3.showInterface=false
46
+target3.type=ClassTarget
47
+target3.width=120
48
+target3.x=70
49
+target3.y=70