Connor Dunnigan 6 年之前
父節點
當前提交
555b8fe30c
共有 3 個檔案被更改,包括 84 行新增2 行删除
  1. 3
    2
      SciCalculator.java
  2. 74
    0
      Units.java
  3. 7
    0
      displayVal.java

+ 3
- 2
SciCalculator.java 查看文件

@@ -12,6 +12,7 @@ public class SciCalculator{
12 12
 
13 13
     Memory memNumber = new Memory();
14 14
     DisplayVal val = new DisplayVal();
15
+    Units unit = new Units();
15 16
 
16 17
     while(isOn){
17 18
         //display prompt
@@ -27,7 +28,7 @@ public class SciCalculator{
27 28
       System.out.println("(2) Execute calculation");
28 29
       System.out.println("(3) Access memory functions (M+, MC, MRC)");
29 30
       System.out.println("(4) Change number system "); //may link to class
30
-      System.out.println("(5) Change units (maybe)"); //may link to class
31
+      System.out.println("(5) Change units"); //may link to class
31 32
       System.out.println("(6) Clear display");
32 33
       System.out.println("------------------------------------------");
33 34
       System.out.println("(7)Quit program");
@@ -80,7 +81,7 @@ public class SciCalculator{
80 81
                 }
81 82
               break;
82 83
         case 5:
83
-                System.out.println("units func");;//clear display
84
+                val.setValue(unit.choice(val.getValue()));//clear display
84 85
               break;
85 86
         case 6:
86 87
                 val.setValue(0.0);

+ 74
- 0
Units.java 查看文件

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

+ 7
- 0
displayVal.java 查看文件

@@ -8,6 +8,8 @@ public class DisplayVal{
8 8
   private String disVal = "0";
9 9
   Scanner stdin = new Scanner(System.in);
10 10
 
11
+  NumSystemsConverter conv = new NumSystemsConverter();
12
+
11 13
 
12 14
   //Scanner stdin = new Scanner(System.in);
13 15
 
@@ -41,6 +43,7 @@ public class DisplayVal{
41 43
               this.numSys = "Hexadecimal";
42 44
             break;
43 45
   }
46
+  this.setDisVal(conv.updateDisplayNumber(this.value,num)); //not working
44 47
 }
45 48
 
46 49
 public void toggleNumSys(){
@@ -62,6 +65,10 @@ public String getNumSys(){
62 65
   return this.numSys;
63 66
 }
64 67
 
68
+public void setDisVal(String value){
69
+  this.disVal = value;
70
+}
71
+
65 72
 
66 73
   public String valToString(double num){
67 74
     String displayStr = new String();