ソースを参照

Check in before demo

Demetrius Murray 6 年 前
コミット
bd7dd3ee78
共有3 個のファイルを変更した97 個の追加96 個の削除を含む
  1. 15
    14
      Console.java
  2. 1
    1
      ConsoleTest.java
  3. 81
    81
      MainApplication.java

+ 15
- 14
Console.java ファイルの表示

@@ -13,7 +13,7 @@ public class Console {
13 13
      */
14 14
     public static double inputDouble()
15 15
     {
16
-        System.out.println("Enter double value");
16
+        System.out.println("Enter a value");
17 17
         double userInput = keyboard.nextDouble();
18 18
         return userInput;
19 19
     }
@@ -136,33 +136,34 @@ public class Console {
136 136
         return isZero;
137 137
     }
138 138
 */
139
-/*
140
-    public static void initialInput()
139
+
140
+  /*  public static String firstInput()
141 141
     {
142 142
         try{
143
-            firstValue = Console.inputString();
143
+            String firstValue = Console.inputString();
144
+            
144 145
             if(firstValue.matches("[0-9]+")){
145
-                currentNum = Double.valueOf(firstValue);
146
+                return String.valueOf(firstValue);
146 147
             }
147
-            else if(firstValue.matches("q"))
148
+            else if(firstValue.equals("q"))
148 149
             {
149
-                Console.quit();
150
+                return "q";
150 151
             }
151
-            else if(firstValue.matches("c"))
152
+            else if(firstValue.equals("c"))
152 153
             {
153
-                currentNum = Console.displayClear();
154
-                currentNum = Double.valueOf(Console.inputString());                
154
+                displayClear();
155
+                return "c";
155 156
             }
156 157
             else{
157 158
                 Console.error();
158
-                currentNum = Console.displayChange();
159
+                return firstInput();
159 160
             }
160 161
         }
161 162
         catch(Exception a)
162 163
         { 
163 164
             System.out.println("An error occured with the last request");
164
-            System.exit(0);
165
+            return firstInput();
165 166
         }          
166
-    }
167
-*/   
167
+    }*/
168
+  
168 169
 }

+ 1
- 1
ConsoleTest.java ファイルの表示

@@ -19,7 +19,7 @@ public class ConsoleTest
19 19
         ByteArrayInputStream in = new ByteArrayInputStream ("7".getBytes());
20 20
         System.setIn(in);
21 21
 
22
-        assertEquals(7,Console.inputDouble(),.000000001);
22
+        assertEquals(Double.valueOf("7"),Console.inputDouble(),.000000001);
23 23
     }
24 24
 
25 25
     @Test

+ 81
- 81
MainApplication.java ファイルの表示

@@ -7,17 +7,17 @@ import java.util.Scanner;
7 7
  * @version (10/19/18 v1.3 6:07PM)
8 8
  */
9 9
 public class MainApplication {
10
-    
10
+
11 11
     public static void main(String[] args) {
12 12
         System.out.println("It's time for the calculator.");
13 13
         Console.printLegend();
14 14
         Calculator calc = new Calculator();
15
-        
15
+
16 16
         double currentNum = 0;
17 17
         double tempNum;
18 18
         String tempString;
19 19
         String firstValue = "";
20
-        
20
+
21 21
         try{
22 22
             firstValue = Console.inputString();
23 23
             if(firstValue.matches("[0-9]+")){
@@ -34,7 +34,7 @@ public class MainApplication {
34 34
             }
35 35
             else{
36 36
                 Console.error();
37
-                currentNum = Console.displayChange();
37
+                currentNum = Double.valueOf(Console.inputString());
38 38
             }
39 39
         }
40 40
         catch(Exception a)
@@ -42,101 +42,101 @@ public class MainApplication {
42 42
             System.out.println("An error occured with the last request");
43 43
             System.exit(0);
44 44
         }  
45
-        
45
+
46 46
         while(String.valueOf(firstValue) != "q") {
47 47
             try{
48 48
                 switch (Console.getOperator()) {
49 49
                     case '+': //takes string input. if statement places memory value into function, else converts to double
50
-                        tempString = Console.inputString();
51
-                        if(tempString.equals("R")){
52
-                            tempNum = calc.getMemory();
53
-                        } else {
54
-                            tempNum = Double.valueOf(tempString);
55
-                        }
56
-                        currentNum = calc.add(currentNum, tempNum);
57
-                        break;
50
+                    tempString = Console.inputString();
51
+                    if(tempString.equals("R")){
52
+                        tempNum = calc.getMemory();
53
+                    } else {
54
+                        tempNum = Double.valueOf(tempString);
55
+                    }
56
+                    currentNum = calc.add(currentNum, tempNum);
57
+                    break;
58 58
                     case '-': //takes string input. if statement places memory value into function, else converts to double
59
-                        tempString = Console.inputString();
60
-                        if(tempString.equals("R")){
61
-                            tempNum = calc.getMemory();
62
-                        } else {
63
-                            tempNum = Double.valueOf(tempString);
64
-                        }
65
-                        currentNum = calc.subtract(currentNum, tempNum);
66
-                            break;
59
+                    tempString = Console.inputString();
60
+                    if(tempString.equals("R")){
61
+                        tempNum = calc.getMemory();
62
+                    } else {
63
+                        tempNum = Double.valueOf(tempString);
64
+                    }
65
+                    currentNum = calc.subtract(currentNum, tempNum);
66
+                    break;
67 67
                     case '*': //takes string input. if statement places memory value into function, else converts to double
68
-                        tempString = Console.inputString();
69
-                        if(tempString.equals("R")){
70
-                            tempNum = calc.getMemory();
71
-                        } else {
72
-                            tempNum = Double.valueOf(tempString);
73
-                        }
74
-                        currentNum = calc.multiply(currentNum, tempNum);
75
-                        break;
68
+                    tempString = Console.inputString();
69
+                    if(tempString.equals("R")){
70
+                        tempNum = calc.getMemory();
71
+                    } else {
72
+                        tempNum = Double.valueOf(tempString);
73
+                    }
74
+                    currentNum = calc.multiply(currentNum, tempNum);
75
+                    break;
76 76
                     case '/': //takes string input. if statement places memory value into function, else converts to double
77
-                        tempString = Console.inputString();
78
-                        if(tempString.equals("R")){
79
-                            tempNum = calc.getMemory();
80
-                        } else {
81
-                            tempNum = Double.valueOf(tempString);
82
-                        }
83
-                        while(tempNum == 0 ){
84
-                            System.out.println("Error, cannot divide by zero. Please ");
85
-                            tempNum = Console.inputDouble();
86
-                        }
87
-                        currentNum = calc.divide(currentNum, tempNum);
88
-                        break;
77
+                    tempString = Console.inputString();
78
+                    if(tempString.equals("R")){
79
+                        tempNum = calc.getMemory();
80
+                    } else {
81
+                        tempNum = Double.valueOf(tempString);
82
+                    }
83
+                    while(tempNum == 0 ){
84
+                        System.out.print("Error, cannot divide by zero. Please ");
85
+                        tempNum = Console.inputDouble();
86
+                    }
87
+                    currentNum = calc.divide(currentNum, tempNum);
88
+                    break;
89 89
                     case '@':
90
-                        currentNum = calc.square(currentNum);
91
-                        break;
90
+                    currentNum = calc.square(currentNum);
91
+                    break;
92 92
                     case '&':
93
-                        currentNum = calc.squareRoot(currentNum);
94
-                        break;
93
+                    currentNum = calc.squareRoot(currentNum);
94
+                    break;
95 95
                     case '^': //takes string input. if statement places memory value into function, else converts to double
96
-                        tempString = Console.inputString();
97
-                        if(tempString.equals("R")){
98
-                            tempNum = calc.getMemory();
99
-                        } else {
100
-                            tempNum = Double.valueOf(tempString);
101
-                        }
102
-                        currentNum = calc.exponent(currentNum, tempNum);
103
-                        break;
96
+                    tempString = Console.inputString();
97
+                    if(tempString.equals("R")){
98
+                        tempNum = calc.getMemory();
99
+                    } else {
100
+                        tempNum = Double.valueOf(tempString);
101
+                    }
102
+                    currentNum = calc.exponent(currentNum, tempNum);
103
+                    break;
104 104
                     case '!':
105
-                        if (currentNum == 0){
106
-                            System.out.println("Error, cannot divide by zero. Press 'c' to clear.");
107
-                            continue;
108
-                        }
109
-                        currentNum = calc.invert(currentNum);
110
-                        break;
105
+                    if (currentNum == 0){
106
+                        System.out.println("Error, cannot divide by zero. Press 'c' to clear.");
107
+                        continue;
108
+                    }
109
+                    currentNum = calc.invert(currentNum);
110
+                    break;
111 111
                     case '#':
112
-                        currentNum = calc.changeSign(currentNum);
113
-                        break;
112
+                    currentNum = calc.changeSign(currentNum);
113
+                    break;
114 114
                     case 'M':
115
-                        calc.storeMemory(currentNum);
116
-                        Console.printMemoryValue(calc.getMemory());
117
-                        continue;
115
+                    calc.storeMemory(currentNum);
116
+                    Console.printMemoryValue(calc.getMemory());
117
+                    continue;
118 118
                     case 'R':
119
-                        Console.printMemoryValue(calc.getMemory());
120
-                        break;
119
+                    Console.printMemoryValue(calc.getMemory());
120
+                    break;
121 121
                     case 'C':
122
-                        calc.clearMemory();
123
-                        Console.printMemoryValue(calc.getMemory());
124
-                        break;
122
+                    calc.clearMemory();
123
+                    Console.printMemoryValue(calc.getMemory());
124
+                    break;
125 125
                     case '~':
126
-                        currentNum = Console.displayChange();
127
-                        break;
126
+                    currentNum = Console.displayChange();
127
+                    break;
128 128
                     case 'c':
129
-                        currentNum = Console.displayClear();
130
-                        currentNum = Double.valueOf(Console.inputString()); //asks for new value
131
-                        continue; //back to top of loop
129
+                    currentNum = Console.displayClear();
130
+                    currentNum = Double.valueOf(Console.inputString()); //asks for new value
131
+                    continue; //back to top of loop
132 132
                     case 'l':
133
-                        Console.printLegend();
134
-                        break;
133
+                    Console.printLegend();
134
+                    break;
135 135
                     case 'q':
136
-                        Console.quit();
137
-                        break;
136
+                    Console.quit();
137
+                    break;
138 138
                     default:
139
-                        Console.errorOperator();
139
+                    Console.errorOperator();
140 140
                 }
141 141
             }
142 142
             /** 
@@ -157,8 +157,8 @@ public class MainApplication {
157 157
         }
158 158
         /*
159 159
         if (Console.inputString() == "c"){
160
-            Console.displayClear();
160
+        Console.displayClear();
161 161
         }
162
-        */
162
+         */
163 163
     }
164 164
 }