소스 검색

Merge branch 'master' of WJB3003/ZCW-MacroLabs-OOP-ScientificCalculator into master

William Brown 6 년 전
부모
커밋
c47e0453a3
3개의 변경된 파일67개의 추가작업 그리고 58개의 파일을 삭제
  1. 12
    8
      Console.java
  2. 24
    19
      opSwitch.java
  3. 31
    31
      simpleOp.java

+ 12
- 8
Console.java 파일 보기

20
         return userInput;
20
         return userInput;
21
     }
21
     }
22
 
22
 
23
-    public static Integer getIntegerInput(String prompt) {
23
+    public static Integer  getIntInput(String prompt) {
24
         Scanner scanner = new Scanner(System.in);
24
         Scanner scanner = new Scanner(System.in);
25
         println(prompt);
25
         println(prompt);
26
         int userInput = scanner.nextInt();
26
         int userInput = scanner.nextInt();
44
         //CLEARS SCREEN / SET TO ZERO ??
44
         //CLEARS SCREEN / SET TO ZERO ??
45
     }
45
     }
46
     
46
     
47
-    public static int getInput(String numberString){
47
+    public static double getInput(String numberString){
48
         //GETS INPUT FROM PERSON ( X )
48
         //GETS INPUT FROM PERSON ( X )
49
             //String numberString = getStringInput("Please choose a number.");
49
             //String numberString = getStringInput("Please choose a number.");
50
             quit(numberString);
50
             quit(numberString);
51
         try{
51
         try{
52
-            int number1 = Integer.parseInt(numberString);
52
+            double number1 = Double.parseDouble(numberString);
53
             //System.out.println(number1);
53
             //System.out.println(number1);
54
             return number1;
54
             return number1;
55
         }catch(Exception e){
55
         }catch(Exception e){
57
         }
57
         }
58
     }
58
     }
59
     /*
59
     /*
60
-    public static int invert(int number){
60
+    public static double invert(double number){
61
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
61
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
62
         try{
62
         try{
63
-            int invertedNumber = -number;
63
+            double invertedNumber = -number;
64
             System.out.println(invertedNumber);
64
             System.out.println(invertedNumber);
65
             return invertedNumber;
65
             return invertedNumber;
66
         } catch(Exception e){
66
         } catch(Exception e){
68
         }
68
         }
69
     }
69
     }
70
     */
70
     */
71
-    public static int getNumber(String numberString){
71
+    public static double getNumber(String numberString){
72
         //GETS INPUT FROM PERSON ( Y )
72
         //GETS INPUT FROM PERSON ( Y )
73
             //System.out.println(first + " " + op);
73
             //System.out.println(first + " " + op);
74
             //String numberString = getStringInput("Please choose a number.");
74
             //String numberString = getStringInput("Please choose a number.");
75
             quit(numberString);
75
             quit(numberString);
76
         try{
76
         try{
77
-            int number2 = Integer.parseInt(numberString);
77
+            double number2 = Double.parseDouble(numberString);
78
             //System.out.println(number2);
78
             //System.out.println(number2);
79
             return number2;
79
             return number2;
80
         }catch(Exception e){
80
         }catch(Exception e){
84
     
84
     
85
     public static String getOp(){
85
     public static String getOp(){
86
         //GET OPERATION FROM PERSON
86
         //GET OPERATION FROM PERSON
87
+            System.out.println("Current Number: " + simpleOp.currentNumber);
87
             String operation = getStringInput("Please choose your operation.");
88
             String operation = getStringInput("Please choose your operation.");
88
             if (operation == null) {
89
             if (operation == null) {
89
                 System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
90
                 System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
96
     
97
     
97
     public static void quit(String answer){
98
     public static void quit(String answer){
98
         if(answer.equals("quit") || answer.equals("exit")){
99
         if(answer.equals("quit") || answer.equals("exit")){
99
-               System.exit(0);
100
+            System.exit(0);
100
         } else if(answer.equals("clear")) {
101
         } else if(answer.equals("clear")) {
101
             System.out.print('\f');
102
             System.out.print('\f');
103
+        } else if(answer.equals("reset")){
104
+            simpleOp.currentNumber = 0;
105
+            System.out.println(simpleOp.currentNumber);
102
         }
106
         }
103
     }
107
     }
104
    
108
    

+ 24
- 19
opSwitch.java 파일 보기

24
                 +"square root"+"\n"
24
                 +"square root"+"\n"
25
                 +"exponent"+"\n"
25
                 +"exponent"+"\n"
26
                 +"inverse"+"\n"
26
                 +"inverse"+"\n"
27
+                +"invert"+"\n"
27
                 +"quit"+"\n"
28
                 +"quit"+"\n"
28
-                +"clear"+"\n");
29
+                +"clear"+"\n"
30
+                +"reset"+"\n");
29
                 break;
31
                 break;
30
             case "+": 
32
             case "+": 
31
                 //x = Console.getStringInput("Please enter first number.");
33
                 //x = Console.getStringInput("Please enter first number.");
33
                 simpleOp.add(op.currentNumber, Console.getNumber(y));
35
                 simpleOp.add(op.currentNumber, Console.getNumber(y));
34
                 break;
36
                 break;
35
             case "-": 
37
             case "-": 
36
-                x = Console.getStringInput("Please enter first number.");
37
-                y = Console.getStringInput("Please enter second number.");
38
-                simpleOp.sub(Console.getNumber(x), Console.getNumber(y));
38
+                //x = Console.getStringInput("Please enter first number.");
39
+                y = Console.getStringInput("Please enter number.");
40
+                simpleOp.sub(op.currentNumber, Console.getNumber(y));
39
                 break;
41
                 break;
40
             case "*": 
42
             case "*": 
41
-                x = Console.getStringInput("Please enter multiplicand.");
42
-                y = Console.getStringInput("Please enter multiplier.");
43
-                simpleOp.mul(Console.getNumber(x), Console.getNumber(y));
43
+                //x = Console.getStringInput("Please enter multiplicand.");
44
+                y = Console.getStringInput("Please enter number.");
45
+                simpleOp.mul(op.currentNumber, Console.getNumber(y));
44
                 break;
46
                 break;
45
             case "/": 
47
             case "/": 
46
-                x = Console.getStringInput("Please enter dividend.");
47
-                y = Console.getStringInput("Please enter divisor.");
48
-                simpleOp.div(Console.getNumber(x), Console.getNumber(y));
48
+                //x = Console.getStringInput("Please enter dividend.");
49
+                y = Console.getStringInput("Please enter number.");
50
+                simpleOp.div(op.currentNumber, Console.getNumber(y));
49
                 break;
51
                 break;
50
             case "square": 
52
             case "square": 
51
-                x = Console.getStringInput("Please enter your number.");
52
-                simpleOp.squ(Console.getNumber(x));
53
+                //x = Console.getStringInput("Please enter your number.");
54
+                simpleOp.squ(op.currentNumber);
53
                 break;
55
                 break;
54
             case "square root": 
56
             case "square root": 
55
-                x = Console.getStringInput("Please enter your number.");
56
-                simpleOp.sqrt(Console.getNumber(x));
57
+                //x = Console.getStringInput("Please enter your number.");
58
+                simpleOp.sqrt(op.currentNumber);
57
                 break;
59
                 break;
58
             case "exponent": 
60
             case "exponent": 
59
-                x = Console.getStringInput("Please enter base.");
60
-                y = Console.getStringInput("Please enter exponent.");
61
-                simpleOp.exp(Console.getNumber(x), Console.getNumber(y));
61
+                //x = Console.getStringInput("Please enter base.");
62
+                y = Console.getStringInput("Please enter the exponent.");
63
+                simpleOp.exp(op.currentNumber, Console.getNumber(y));
62
                 break;
64
                 break;
63
             case "inverse":
65
             case "inverse":
64
-                x = Console.getStringInput("Please enter your number.");
65
-                simpleOp.inv(Console.getNumber(x));
66
+                //x = Console.getStringInput("Please enter your number.");
67
+                simpleOp.inv(op.currentNumber);
68
+                break;
69
+            case "invert":
70
+                simpleOp.invert(op.currentNumber);
66
                 break;
71
                 break;
67
             // default:
72
             // default:
68
                 // System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");
73
                 // System.out.println("You have not provided valid input. Please enter \"?\" for a list of commands.");

+ 31
- 31
simpleOp.java 파일 보기

8
 import java.util.*;
8
 import java.util.*;
9
 public class simpleOp
9
 public class simpleOp
10
 {
10
 {
11
-    public static int currentNumber = 0;
11
+    public static double currentNumber = 0;
12
     
12
     
13
-    public static int add(int x, int y){
13
+    public static double add(double x, double y){
14
         //CALULATES THE SUM OF TWO NUMBERS
14
         //CALULATES THE SUM OF TWO NUMBERS
15
         currentNumber = x + y;
15
         currentNumber = x + y;
16
-        System.out.println(currentNumber);
16
+        //System.out.println(currentNumber);
17
         return currentNumber;
17
         return currentNumber;
18
     }
18
     }
19
     
19
     
20
-    public static int sub(int x, int y){
20
+    public static double sub(double x, double y){
21
         //CALULATES THE DIFFERENCE OF TWO NUMBERS
21
         //CALULATES THE DIFFERENCE OF TWO NUMBERS
22
-        int currentNumber = x - y;
23
-        System.out.println(x + " - " + y + " = " + currentNumber);
22
+        currentNumber = x - y;
23
+        //System.out.println(currentNumber);
24
         return currentNumber;
24
         return currentNumber;
25
     }
25
     }
26
     
26
     
27
-    public static int mul(int x, int y){
27
+    public static double mul(double x, double y){
28
         //CALULATES THE PRODUCT OF TWO NUMBERS
28
         //CALULATES THE PRODUCT OF TWO NUMBERS
29
-        int currentNumber = x * y;
30
-        System.out.println(x + " * " + y + " = " + currentNumber);
29
+        currentNumber = x * y;
30
+        //System.out.println(currentNumber);
31
         return currentNumber;
31
         return currentNumber;
32
     }
32
     }
33
     
33
     
34
-    public static int div(int x, int y){
34
+    public static double div(double x, double y){
35
         //CALULATES THE QUOTIENT OF TWO NUMBERS
35
         //CALULATES THE QUOTIENT OF TWO NUMBERS
36
-        int currentNumber = x / y;
37
-        System.out.println(x + " / " + y + " = " + currentNumber);
36
+        currentNumber = x / y;
37
+        //System.out.println(currentNumber);
38
         return currentNumber;
38
         return currentNumber;
39
     }
39
     }
40
     
40
     
41
-    public static int squ(int x){
41
+    public static double squ(double x){
42
         //CALULATES THE SQUARE OF ONE NUMBER
42
         //CALULATES THE SQUARE OF ONE NUMBER
43
-        //CASTED TO INT FOR NOW... IT'S IN ALPHA, YOU DIG?
44
-        int currentNumber = (int) Math.pow(x,2);
45
-        System.out.println(x + "\u00B2 = " + currentNumber);
43
+        //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
44
+        currentNumber = (int) Math.pow(x,2);
45
+        //System.out.println(currentNumber);
46
         return currentNumber;
46
         return currentNumber;
47
     }
47
     }
48
     
48
     
49
-    public static int sqrt(int x){
49
+    public static double sqrt(double x){
50
         //CALULATES THE SQUARE ROOT OF ONE NUMBER
50
         //CALULATES THE SQUARE ROOT OF ONE NUMBER
51
-        //CASTED TO INT FOR NOW... IT'S IN ALPHA, YOU DIG?
52
-        int currentNumber = (int) Math.sqrt(x);
53
-        System.out.println("√" + x + " = " + currentNumber);
51
+        //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
52
+        currentNumber = (int) Math.sqrt(x);
53
+        //System.out.println(currentNumber);
54
         return currentNumber;
54
         return currentNumber;
55
     }
55
     }
56
     
56
     
57
-    public static int exp(int x, int y){
57
+    public static double exp(double x, double y){
58
         //CALULATES EXPONENTIATION OF X TO POWER OF Y
58
         //CALULATES EXPONENTIATION OF X TO POWER OF Y
59
-        //CASTED TO INT FOR NOW... IT'S IN ALPHA, YOU DIG?
60
-        int currentNumber = (int) Math.pow(x,y);
61
-        System.out.println(x + "^" + y + " = " + currentNumber);
59
+        //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
60
+        currentNumber = (int) Math.pow(x,y);
61
+        //System.out.println(currentNumber);
62
         return currentNumber;
62
         return currentNumber;
63
     }
63
     }
64
     
64
     
65
     public static double inv(double x){
65
     public static double inv(double x){
66
         //CALULATES THE INVERSE OF NUMBER
66
         //CALULATES THE INVERSE OF NUMBER
67
-        //CASTED TO INT FOR NOW... IT'S IN ALPHA, YOU DIG?
68
-        double currentNumber = 1 / x;
69
-        System.out.println("1 / " + x + " = " + currentNumber);
67
+        //CASTED TO double FOR NOW... IT'S IN ALPHA, YOU DIG?
68
+        currentNumber = (1/x);
69
+        //System.out.println(currentNumber);
70
         return currentNumber;
70
         return currentNumber;
71
     }
71
     }
72
     
72
     
73
-    public static int invert(int number){
73
+    public static double invert(double x){
74
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
74
         //TURNS NEGATIVE TO POSITIVE OR POSITIVE TO NEGATIVE
75
-            currentNumber = -number;
76
-            System.out.println(currentNumber);
77
-            return currentNumber;
75
+        currentNumber = -x;
76
+        //System.out.println(currentNumber);
77
+        return currentNumber;
78
     }
78
     }
79
     
79
     
80
 }
80
 }