Connor Dunnigan 6 år sedan
förälder
incheckning
b317f41782
3 ändrade filer med 66 tillägg och 38 borttagningar
  1. 20
    4
      Operations.java
  2. 32
    24
      SciCalculator.java
  3. 14
    10
      displayVal.java

+ 20
- 4
Operations.java Visa fil

@@ -5,15 +5,16 @@ public class Operations{
5 5
 
6 6
   Scanner stdin = new Scanner(System.in);
7 7
 
8
-
9 8
 public double chooseOp(double num){
10 9
 
11 10
   boolean isValid = false;
12 11
   int choice;
13
-  double result = -1;
12
+  double result = 0;
14 13
 
15 14
   while(!isValid){
16 15
     System.out.println("\n-------------------------------------------------");
16
+    System.out.println(num);
17
+    System.out.println("-------------------------------------------------");
17 18
     System.out.println("Select type of operation to perform (enter # 1-3)");
18 19
     System.out.println("(1) Core Functions");
19 20
     System.out.println("(2) Trigonometry");
@@ -47,7 +48,9 @@ public double coreFunc(double num){ //take displayNum as input parameter
47 48
 
48 49
 
49 50
   while(!isValid){
50
-    System.out.println("\n---------------------------------------------");
51
+    System.out.println("\n-------------------------------------------------");
52
+    System.out.println(num);
53
+    System.out.println("-------------------------------------------------");
51 54
     System.out.println("Select core function to perform (enter # 1-9)");
52 55
     System.out.println("(1) Add");
53 56
     System.out.println("(2) Subtract");
@@ -64,43 +67,52 @@ public double coreFunc(double num){ //take displayNum as input parameter
64 67
 
65 68
     switch(choice){
66 69
       case 1: System.out.println("Enter number to add to " + num + ": ");
70
+              System.out.print("> ");
67 71
               entNum = stdin.nextDouble();
68 72
               result = num + entNum;
69 73
               isValid = true;
70 74
             break;
71 75
       case 2: System.out.println("Enter number to subtract from " + num + ": ");
76
+              System.out.print("> ");
72 77
               entNum = stdin.nextDouble();
73 78
               result = num - entNum;
74 79
               isValid = true;
75 80
             break;
76 81
       case 3: System.out.println("Enter number to multiply to " + num + ": ");
82
+              System.out.print("> ");
77 83
               entNum = stdin.nextDouble();
78 84
               result = num * entNum;
79 85
               isValid = true;
80 86
             break;
81 87
       case 4: System.out.println("Enter number to divide from " + num + ": ");
88
+              System.out.print("> ");
82 89
               entNum = stdin.nextDouble();
83 90
               result = num / entNum; //use Double.isNaN(x)
84 91
               isValid = true;
85 92
             break;
86 93
       case 5: System.out.println("Squaring number on display (" + num + "^2) ");
94
+              System.out.print("> ");
87 95
               result = num * num;
88 96
               isValid = true;
89 97
             break;
90 98
       case 6: System.out.println("Taking square root of " + num);//cant take negative #
99
+              System.out.print("> ");
91 100
               result = Math.sqrt(num);
92 101
               isValid = true;
93 102
             break;
94 103
       case 7: System.out.println("Enter exponent to raise " + num + " to (" + num + "^n)");
104
+              System.out.print("> ");
95 105
               entNum = stdin.nextDouble();
96 106
               result = num * entNum;
97 107
               isValid = true;
98 108
             break;
99 109
       case 8: System.out.println("Calculating inverse of " + num + " (1/" + num + ")");
110
+              System.out.print("> ");
100 111
               result = 1/num;
101 112
               isValid = true;
102 113
             break;
103 114
       case 9: System.out.println("Calculating negation of  " + num + " (n -> -n , -n -> n)");
115
+              System.out.print("> ");
104 116
               result = num * -1;
105 117
               isValid = true;
106 118
             break;
@@ -119,7 +131,9 @@ public double trigFunc(double num){ //take displayNum as input parameter
119 131
   double result = -0;
120 132
 
121 133
   while(!isValid){
122
-    System.out.println("\n--------------------------------------------");
134
+    System.out.println("\n-------------------------------------------------");
135
+    System.out.println(num);
136
+    System.out.println("-------------------------------------------------");
123 137
     System.out.println("Select trigonemtric function (enter # 1-6)");
124 138
     System.out.println("(1) Sin");
125 139
     System.out.println("(2) Cos");
@@ -170,6 +184,8 @@ public double advFunc(double num){ //take displayNum as input parameter
170 184
 
171 185
   while(!isValid){
172 186
     System.out.println("\n-------------------------------------------------");
187
+    System.out.println(num);
188
+    System.out.println("-------------------------------------------------");
173 189
     System.out.println("Select advanced function to perform (enter # 1-7)");
174 190
     System.out.println("(1) Factorial");
175 191
     System.out.println("(2) Log");

+ 32
- 24
SciCalculator.java Visa fil

@@ -9,60 +9,68 @@ public class SciCalculator{
9 9
 
10 10
     boolean isOn = true;
11 11
     int choice;
12
-    double displayNumber = 0;
13 12
 
14 13
     Memory memNumber = new Memory();
14
+    DisplayVal val = new DisplayVal();
15 15
 
16 16
     while(isOn){
17 17
         //display prompt
18 18
       System.out.println("\n******************************************");
19
-      System.out.println(String.format("%"+32+"s", "Scientific Calculator"));
19
+      System.out.println(String.format("%"+30+"s", "Scientific Calculator"));
20 20
       System.out.println("------------------------------------------");
21
-      System.out.println(displayNumber);
21
+      System.out.println(val.valToString(val.getValue()));
22 22
       System.out.println("==========================================");
23 23
       System.out.println("Please choose a function (enter # 1-6)");
24
-      System.out.println("(1) Change units");
25
-      System.out.println("(2) Change number system");
24
+      System.out.println("(1) Input value to calculator");
25
+      System.out.println("(2) Execute calculation");
26 26
       System.out.println("(3) Access memory functions (M+, MC, MRC)");
27
-      System.out.println("(4) Execute calculation");
28
-      System.out.println("(5) Clear display");
27
+      System.out.println("(4) Change number system (maybe)"); //may link to class
28
+      System.out.println("(5) Change units (maybe)"); //may link to class
29
+      System.out.println("(6) Clear display");
29 30
       System.out.println("------------------------------------------");
30
-      System.out.println("(6)Quit program");
31
+      System.out.println("(7)Quit program");
31 32
       System.out.println("******************************************");
32 33
       System.out.print("> ");
33 34
 
34 35
       choice = stdin.nextInt();
35 36
 
36 37
       switch(choice){
37
-        case 1:System.out.println("call change units function");//call change units function
38
-                break;
39
-        case 2:System.out.println("call number system function");//call number system function
40
-                break;
41
-        case 3: System.out.println("------------------------------------------");
38
+        case 1: System.out.println("Enter the value you want to input to calculator:");//call change units function
39
+                System.out.print("> ");
40
+                double inVal = stdin.nextDouble();
41
+                val.setValue(inVal);
42
+              break;
43
+        case 2: Operations op = new Operations();
44
+                val.setValue(op.chooseOp(val.getValue()));//call operations function
45
+              break;
46
+        case 3: System.out.println("\n------------------------------------------");
42 47
                 System.out.println("Choose memory function (enter 1 or 2)");
43 48
                 System.out.println("(1) Recall value in memory");
44 49
                 System.out.println("(2) Update value in memory");
45 50
                 System.out.println("------------------------------------------");
46 51
                 System.out.print("> ");
47 52
                 int mem = stdin.nextInt();
48
-                if(mem == 1)
49
-                  displayNumber = memNumber.getMemNum();
50
-                else if(mem == 2)
53
+                if(mem == 1){
54
+                  val.setValue(memNumber.getMemNum());
55
+                }
56
+                else if(mem == 2){
51 57
                   memNumber.setMemNum();
58
+                }
52 59
                 else{
53 60
                   System.out.println("Value in memory is: " + memNumber.getMemNum());
54 61
                 }
55 62
                 break;
56
-        case 4: Operations op = new Operations();
57
-                displayNumber = op.chooseOp(displayNumber);//call operations function
58
-                break;
59
-        case 5:System.out.println("clear display");//clear display
60
-                break;
61
-        case 6:System.out.println("Goodbye");//clear display
63
+        case 4: System.out.println("maybe number systems func");//clear display
64
+              break;
65
+        case 5: System.out.println("change units function (maybe)");//clear display
66
+              break;
67
+        case 6: System.out.println("clear display function");
68
+              break;
69
+        case 7:System.out.println("Goodbye");//clear display
62 70
                 isOn = false;
63
-                break;
71
+              break;
64 72
         default:
65
-                break;
73
+              break;
66 74
       }
67 75
     }
68 76
   }

+ 14
- 10
displayVal.java Visa fil

@@ -1,18 +1,22 @@
1 1
 import java.util.Scanner;
2 2
 import java.lang.*;
3 3
 
4
-public class displayVal{
4
+public class DisplayVal{
5 5
 
6
-  Scanner stdin = new Scanner(System.in);
7
-  private double displayValue = 0;
6
+  private double value = 0;
8 7
 
9
-  public double getMemNum(){
10
-     return this.memNum;
8
+  //Scanner stdin = new Scanner(System.in);
9
+
10
+  public double getValue(){
11
+     return this.value;
12
+  }
13
+  public void setValue(double num){
14
+    this.value = num;
11 15
   }
12
-  public void setMemNum(){
13
-    System.out.println("Enter number to store to memory");
14
-    System.out.print("> ");
15
-    double num = stdin.nextDouble();
16
-    this.memNum = num;
16
+
17
+  public String valToString(double num){
18
+    String displayStr = new String();
19
+    displayStr += "" + num;
20
+    return displayStr;
17 21
   }
18 22
 }