Browse Source

fixed how input works

NedRedmond 6 years ago
parent
commit
cf1d611019
4 changed files with 51 additions and 47 deletions
  1. 2
    2
      Console.java
  2. 5
    3
      opSwitch.java
  3. 15
    15
      package.bluej
  4. 29
    27
      simpleOp.java

+ 2
- 2
Console.java View File

50
             quit(numberString);
50
             quit(numberString);
51
         try{
51
         try{
52
             int number1 = Integer.parseInt(numberString);
52
             int number1 = Integer.parseInt(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){
56
             return getInput(numberString);
56
             return getInput(numberString);
75
             quit(numberString);
75
             quit(numberString);
76
         try{
76
         try{
77
             int number2 = Integer.parseInt(numberString);
77
             int number2 = Integer.parseInt(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){
81
             return getNumber(numberString);
81
             return getNumber(numberString);

+ 5
- 3
opSwitch.java View File

8
 public class opSwitch
8
 public class opSwitch
9
 {
9
 {
10
     public static void choose(String opInput){
10
     public static void choose(String opInput){
11
+        simpleOp op = new simpleOp();
12
+        
11
         String x;
13
         String x;
12
         String y;
14
         String y;
13
         // switchboard for operations
15
         // switchboard for operations
26
                 +"clear"+"\n");
28
                 +"clear"+"\n");
27
                 break;
29
                 break;
28
             case "+": 
30
             case "+": 
29
-                x = Console.getStringInput("Please enter first number.");
30
-                y = Console.getStringInput("Please enter second number.");
31
-                simpleOp.add(Console.getNumber(x), Console.getNumber(y));
31
+                //x = Console.getStringInput("Please enter first number.");
32
+                y = Console.getStringInput("Please enter number.");
33
+                simpleOp.add(op.currentNumber, Console.getNumber(y));
32
                 break;
34
                 break;
33
             case "-": 
35
             case "-": 
34
                 x = Console.getStringInput("Please enter first number.");
36
                 x = Console.getStringInput("Please enter first number.");

+ 15
- 15
package.bluej View File

16
 dependency5.type=UsesDependency
16
 dependency5.type=UsesDependency
17
 editor.fx.0.height=711
17
 editor.fx.0.height=711
18
 editor.fx.0.width=811
18
 editor.fx.0.width=811
19
-editor.fx.0.x=469
20
-editor.fx.0.y=23
19
+editor.fx.0.x=585
20
+editor.fx.0.y=114
21
 objectbench.height=199
21
 objectbench.height=199
22
 objectbench.width=444
22
 objectbench.width=444
23
 package.divider.horizontal=0.6
23
 package.divider.horizontal=0.6
24
 package.divider.vertical=0.6845329249617151
24
 package.divider.vertical=0.6845329249617151
25
 package.editor.height=440
25
 package.editor.height=440
26
 package.editor.width=342
26
 package.editor.width=342
27
-package.editor.x=0
28
-package.editor.y=23
27
+package.editor.x=35
28
+package.editor.y=81
29
 package.frame.height=711
29
 package.frame.height=711
30
 package.frame.width=468
30
 package.frame.width=468
31
 package.numDependencies=5
31
 package.numDependencies=5
45
 target1.width=80
45
 target1.width=80
46
 target1.x=130
46
 target1.x=130
47
 target1.y=220
47
 target1.y=220
48
-target2.association=ConsoleTest
49
 target2.height=50
48
 target2.height=50
50
-target2.name=Console
49
+target2.name=opSwitch
51
 target2.showInterface=false
50
 target2.showInterface=false
52
 target2.type=ClassTarget
51
 target2.type=ClassTarget
53
 target2.width=80
52
 target2.width=80
54
-target2.x=130
55
-target2.y=100
53
+target2.x=40
54
+target2.y=160
55
+target3.association=ConsoleTest
56
 target3.height=50
56
 target3.height=50
57
-target3.name=opSwitch
57
+target3.name=Console
58
 target3.showInterface=false
58
 target3.showInterface=false
59
 target3.type=ClassTarget
59
 target3.type=ClassTarget
60
 target3.width=80
60
 target3.width=80
61
-target3.x=40
62
-target3.y=160
61
+target3.x=130
62
+target3.y=100
63
 target4.height=50
63
 target4.height=50
64
 target4.name=ConsoleTest
64
 target4.name=ConsoleTest
65
 target4.showInterface=false
65
 target4.showInterface=false
67
 target4.width=80
67
 target4.width=80
68
 target4.x=160
68
 target4.x=160
69
 target4.y=70
69
 target4.y=70
70
-target5.height=50
70
+target5.height=40
71
 target5.name=MainApplication
71
 target5.name=MainApplication
72
 target5.showInterface=false
72
 target5.showInterface=false
73
 target5.type=ClassTarget
73
 target5.type=ClassTarget
74
-target5.width=120
75
-target5.x=120
76
-target5.y=10
74
+target5.width=60
75
+target5.x=80
76
+target5.y=30

+ 29
- 27
simpleOp.java View File

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