|
@@ -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
|
|
@@ -14,6 +13,7 @@ public class Trig
|
14
|
13
|
|
15
|
14
|
public Trig()
|
16
|
15
|
{
|
|
16
|
+ //a check to make sure user input is valid
|
17
|
17
|
boolean validInput = false;
|
18
|
18
|
|
19
|
19
|
while(!validInput) {
|
|
@@ -25,58 +25,63 @@ public class Trig
|
25
|
25
|
int input = Console.getIntegerInput("What number would you like to find the " + operation + " of?");
|
26
|
26
|
|
27
|
27
|
//Do the math depending on the input.
|
|
28
|
+ //SIN
|
28
|
29
|
if (operation.equals("sin")) {
|
29
|
30
|
answer = Math.sin(input);
|
30
|
|
- System.out.println(answer);
|
|
31
|
+ Console.println(Double.toString(answer));
|
31
|
32
|
validInput = true;
|
32
|
33
|
|
|
34
|
+ //COS
|
33
|
35
|
} else if (operation.equals("cos")) {
|
34
|
36
|
answer = Math.cos(input);
|
35
|
|
- System.out.println(answer);
|
|
37
|
+ Console.println(Double.toString(answer));
|
36
|
38
|
validInput = true;
|
37
|
39
|
|
|
40
|
+ //TAN
|
38
|
41
|
} else if (operation.equals("tan")) {
|
39
|
42
|
answer = Math.tan(input);
|
40
|
|
- System.out.println(answer);
|
|
43
|
+ Console.println(Double.toString(answer));
|
41
|
44
|
validInput = true;
|
42
|
45
|
|
|
46
|
+ //ARCSIN
|
43
|
47
|
} else if (operation.equals("arcsin")) {
|
44
|
48
|
answer = Math.asin(input);
|
45
|
|
- System.out.println(answer);
|
|
49
|
+ Console.println(Double.toString(answer));
|
46
|
50
|
validInput = true;
|
47
|
51
|
|
|
52
|
+ //ARCCOS
|
48
|
53
|
} else if (operation.equals("arccos")) {
|
49
|
54
|
answer = Math.acos(input);
|
50
|
|
- System.out.println(answer);
|
|
55
|
+ Console.println(Double.toString(answer));
|
51
|
56
|
validInput = true;
|
52
|
57
|
|
|
58
|
+ //ARCTAN
|
53
|
59
|
} else if (operation.equals("arctan")) {
|
54
|
60
|
answer = Math.atan(input);
|
55
|
|
- System.out.println(answer);
|
|
61
|
+ Console.println(Double.toString(answer));
|
56
|
62
|
validInput = true;
|
57
|
|
-
|
|
63
|
+
|
|
64
|
+ //Error message if input does not match options, loops back to the top so they can try again.
|
58
|
65
|
} else {
|
59
|
|
- System.out.println("Error, try again \n");
|
|
66
|
+ Console.println("Error, try again \n");
|
60
|
67
|
|
61
|
68
|
}
|
62
|
69
|
}
|
63
|
70
|
//Ask if they would like to convert.
|
64
|
|
- System.out.println("Would you like to convert your answer from radian to degrees? Y or N");
|
65
|
|
- Scanner in3 = new Scanner(System.in);
|
66
|
|
- String response = in3.nextLine();
|
|
71
|
+ String response = Console.getStringInput("Would you like to convert your answer from radian to degrees? Y or N");
|
67
|
72
|
response = response.toLowerCase();
|
68
|
73
|
if (response.equals("y")) {
|
69
|
74
|
toDegrees(answer);
|
70
|
75
|
} else {
|
71
|
|
- System.out.println("Have a nice day!");
|
|
76
|
+ Console.println("Have a nice day!");
|
72
|
77
|
//Insert Return to Main Menu
|
73
|
78
|
}
|
74
|
79
|
}
|
75
|
|
-
|
|
80
|
+ //Converting from Radians to Degrees
|
76
|
81
|
public void toDegrees(double answer)
|
77
|
82
|
{
|
78
|
83
|
double conversion = Math.toDegrees(answer);
|
79
|
|
- System.out.println(conversion);
|
|
84
|
+ Console.println(Double.toString(conversion));
|
80
|
85
|
//Insert Return to Main Menu
|
81
|
86
|
}
|
82
|
87
|
}
|