|
@@ -0,0 +1,74 @@
|
|
1
|
+import java.util.Scanner;
|
|
2
|
+
|
|
3
|
+public class Units
|
|
4
|
+{
|
|
5
|
+
|
|
6
|
+Scanner units = new Scanner(System.in);
|
|
7
|
+
|
|
8
|
+ public double choice (double num) {
|
|
9
|
+
|
|
10
|
+ boolean isValid = false;
|
|
11
|
+ int modechoice = 0;
|
|
12
|
+ double result = 0;
|
|
13
|
+
|
|
14
|
+ while(!isValid){
|
|
15
|
+ System.out.println("\n-------------------------------------------------");
|
|
16
|
+ System.out.println(num);
|
|
17
|
+ System.out.println("-------------------------------------------------");
|
|
18
|
+ System.out.println("Select which unit you would like to convert to (enter #1 or #2)");
|
|
19
|
+ System.out.println("(1) Degrees");
|
|
20
|
+ System.out.println("(2) Radians");
|
|
21
|
+ System.out.println("--------------------------------------------");
|
|
22
|
+ System.out.print("> ");
|
|
23
|
+ modechoice = units.nextInt();
|
|
24
|
+
|
|
25
|
+ switch(modechoice){
|
|
26
|
+ case 1: result = this.degrees(num);
|
|
27
|
+ isValid = true;
|
|
28
|
+ break;
|
|
29
|
+ case 2: result = this.radians(num);
|
|
30
|
+ isValid = true;
|
|
31
|
+ break; }
|
|
32
|
+ }
|
|
33
|
+ return result;
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ public double degrees (double num) {
|
|
37
|
+
|
|
38
|
+ System.out.println("Please enter your value for degree conversion");
|
|
39
|
+
|
|
40
|
+ boolean isValid = false;
|
|
41
|
+ double output = 0;
|
|
42
|
+ double input = units.nextInt();
|
|
43
|
+
|
|
44
|
+ if (!Double.isNaN(num)) {
|
|
45
|
+ System.out.println("Calculating degrees of " + input);
|
|
46
|
+ num = Math.toDegrees(input);
|
|
47
|
+ System.out.println(num);}
|
|
48
|
+ else {
|
|
49
|
+ System.out.println("Please enter your value");
|
|
50
|
+ }
|
|
51
|
+ return num;
|
|
52
|
+ };
|
|
53
|
+ public double radians (double num) {
|
|
54
|
+
|
|
55
|
+ System.out.println("Please enter your value for radian conversion");
|
|
56
|
+
|
|
57
|
+ boolean isValid = true;
|
|
58
|
+ double output = 0;
|
|
59
|
+ double input = units.nextInt();
|
|
60
|
+
|
|
61
|
+ if (!Double.isNaN(num)) {
|
|
62
|
+ System.out.println("Calculating radians of " + input);
|
|
63
|
+ num = Math.toRadians(input);
|
|
64
|
+ System.out.println(num);}
|
|
65
|
+ else {
|
|
66
|
+ System.out.println("Please enter your value");
|
|
67
|
+ }
|
|
68
|
+ return num;
|
|
69
|
+
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+}
|