|
@@ -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
|
+
|