Arin Turpin 6 лет назад
Родитель
Сommit
026443383f
7 измененных файлов: 250 добавлений и 36 удалений
  1. 9
    3
      Console.java
  2. 71
    0
      CoreFeatures.java
  3. 47
    8
      MainApplication.java
  4. 0
    0
      README.TXT
  5. 33
    0
      ScientificFeatures.java
  6. 33
    0
      TrigFeatures.java
  7. 57
    25
      package.bluej

+ 9
- 3
Console.java Просмотреть файл

@@ -6,7 +6,10 @@ import java.util.Scanner;
6 6
  * Created by leon on 2/9/18.
7 7
  */
8 8
 public class Console {
9
-
9
+    
10
+    public static double result = 0;
11
+    public static boolean calcRunning = true;
12
+    
10 13
     public static void print(String output, Object... args) {
11 14
         System.out.printf(output, args);
12 15
     }
@@ -17,7 +20,7 @@ public class Console {
17 20
 
18 21
     public static String getStringInput(String prompt) {
19 22
         Scanner scanner = new Scanner(System.in);
20
-        println(prompt);
23
+        System.out.print(prompt);
21 24
         String userInput = scanner.nextLine();
22 25
         return userInput;
23 26
     }
@@ -27,6 +30,9 @@ public class Console {
27 30
     }
28 31
 
29 32
     public static Double getDoubleInput(String prompt) {
30
-        return null;
33
+       System.out.print(prompt);
34
+        Scanner scanner = new Scanner(System.in);
35
+        double userInput = scanner.nextDouble();
36
+        return userInput;
31 37
     }
32 38
 }

+ 71
- 0
CoreFeatures.java Просмотреть файл

@@ -0,0 +1,71 @@
1
+
2
+/**
3
+ * Write a description of class CoreFeatures here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class CoreFeatures extends MainApplication {
9
+    // instance variables - replace the example below with your own
10
+    private double x;
11
+    private double addedNumbers;
12
+    //addition
13
+    private double subtractedNumbers;
14
+    //subtraction
15
+    private double multipliedNumbers;
16
+    //multiplication
17
+    private double dividedNumbers;
18
+    //divide
19
+    private double squaredNumber;
20
+    //square
21
+    private double sqRt;
22
+    //square root
23
+    private boolean calcRunning;
24
+
25
+    /**
26
+     * Constructor for objects of class CoreFeatures
27
+     */
28
+    public CoreFeatures(){
29
+        // initialise instance variables
30
+        x = 0;
31
+    }
32
+
33
+    public double addNumbers(double adding1, double adding2){
34
+        addedNumbers = adding1 + adding2;
35
+        return addedNumbers;}
36
+
37
+    public double subtractNumbers(double subtracting1, double subtracting2){
38
+        subtractedNumbers = subtracting1 - subtracting2;
39
+        return subtractedNumbers;}
40
+
41
+    public double multiplyNumbers(double multiplying1, double multiplying2){
42
+        multipliedNumbers = multiplying1 * multiplying2;
43
+        return multipliedNumbers;}
44
+
45
+    public double divideNumbers(double dividing1, double dividing2){
46
+        if (dividing2 = 0){
47
+            System.out.println("**ERROR** CANNOT DIVIDE BY ZERO.");} else {
48
+            dividedNumbers = dividing1 / dividing2;
49
+            return dividedNumbers;}
50
+
51
+        /*double userCorrectedInput = Console.getDoubleInput("**Err** CANNOT DIVIDE BY ZERO.  Please clear the calculator.");
52
+        return userCorrectedInput;*/
53
+
54
+        /*dividedNumbers = dividing1 / dividing2;
55
+        return dividedNumbers;*/
56
+    }
57
+
58
+    public double squareNumber(double squaring){
59
+        squaredNumber = squaring * squaring;
60
+        return squaredNumber;}
61
+
62
+    public double squareRoot(double sqRting){
63
+        sqRt = squareRoot(sqRting);
64
+        return sqRt;}
65
+
66
+    public boolean calcRunning(){
67
+        calcRunning = false;
68
+        return calcRunning;
69
+    }
70
+
71
+}

+ 47
- 8
MainApplication.java Просмотреть файл

@@ -1,17 +1,56 @@
1
- 
2 1
 
3 2
 /**
4 3
  * Created by leon on 2/9/18.
5 4
  */
5
+
6 6
 public class MainApplication {
7
+    private void commandCenter(){
8
+        //All the different feature objects
9
+        CoreFeatures switchCoreFeatures = new CoreFeatures();
10
+        
11
+        //User instructions 
12
+       String userInput = Console.getStringInput("Choose a symbol for the corresponding function : " + "\n"
13
+       + " |'+' = addition|" + "\n"+
14
+       "|'-' = subtraction|");
15
+        
16
+    switch(userInput){
17
+    case "+": 
18
+    double userInput2 = Console.getDoubleInput("Enter number to be added. ");
19
+    Console.result = switchCoreFeatures.addNumbers(Console.result, userInput2);
20
+    System.out.println(Console.result);
21
+    break;
22
+    
23
+    case "-":
24
+    double userInput3 = Console.getDoubleInput("Enter number to be subtracted. ");
25
+    Console.result = switchCoreFeatures.subtractNumbers(Console.result, userInput3);
26
+    System.out.println(Console.result);
27
+    break;
28
+    
29
+    case "*":
30
+    double userInput4 = Console.getDoubleInput("Enter number to be multiplied. ");
31
+    Console.result = switchCoreFeatures.multiplyNumbers(Console.result, userInput4);
32
+    System.out.println(Console.result);
33
+    break;
34
+    
35
+    case "off":
36
+    Console.calcRunning = false;
37
+    break;
38
+    
39
+    }
40
+}
7 41
     public static void main(String[] args) {
8 42
         Console.println("Welcome to my calculator!");
9
-        String s = Console.getStringInput("Enter a string");
10
-        Integer i = Console.getIntegerInput("Enter an integer");
11
-        Double d = Console.getDoubleInput("Enter a double.");
12
-
13
-        Console.println("The user input %s as a string", s);
14
-        Console.println("The user input %s as a integer", i);
15
-        Console.println("The user input %s as a d", d);
43
+        MainApplication mainApplication = new MainApplication();
44
+        //String s = Console.getStringInput("Enter a string");
45
+        //Integer i = Console.getIntegerInput("Enter an integer");
46
+        //Double d = Console.getDoubleInput("Enter a double.");
47
+        
48
+        
49
+        while (Console.calcRunning){
50
+            //some sort of commads that take user input for a number
51
+            mainApplication.commandCenter();
52
+        
53
+        }
54
+        
16 55
     }
17 56
 }

+ 0
- 0
README.TXT Просмотреть файл


+ 33
- 0
ScientificFeatures.java Просмотреть файл

@@ -0,0 +1,33 @@
1
+
2
+/**
3
+ * Write a description of class ScientificFeatures here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class ScientificFeatures extends MainApplication
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class ScientificFeatures
15
+     */
16
+    public ScientificFeatures()
17
+    {
18
+        // initialise instance variables
19
+        x = 0;
20
+    }
21
+
22
+    /**
23
+     * An example of a method - replace this comment with your own
24
+     *
25
+     * @param  y  a sample parameter for a method
26
+     * @return    the sum of x and y
27
+     */
28
+    public int sampleMethod(int y)
29
+    {
30
+        // put your code here
31
+        return x + y;
32
+    }
33
+}

+ 33
- 0
TrigFeatures.java Просмотреть файл

@@ -0,0 +1,33 @@
1
+
2
+/**
3
+ * Write a description of class TrigFeatures here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class TrigFeatures extends MainApplication
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class TrigFeatures
15
+     */
16
+    public TrigFeatures()
17
+    {
18
+        // initialise instance variables
19
+        x = 0;
20
+    }
21
+
22
+    /**
23
+     * An example of a method - replace this comment with your own
24
+     *
25
+     * @param  y  a sample parameter for a method
26
+     * @return    the sum of x and y
27
+     */
28
+    public int sampleMethod(int y)
29
+    {
30
+        // put your code here
31
+        return x + y;
32
+    }
33
+}

+ 57
- 25
package.bluej Просмотреть файл

@@ -1,23 +1,26 @@
1 1
 #BlueJ package file
2 2
 dependency1.from=MainApplication
3
-dependency1.to=Console
3
+dependency1.to=CoreFeatures
4 4
 dependency1.type=UsesDependency
5
-editor.fx.0.height=722
6
-editor.fx.0.width=800
7
-editor.fx.0.x=640
8
-editor.fx.0.y=23
9
-objectbench.height=214
10
-objectbench.width=595
5
+dependency2.from=MainApplication
6
+dependency2.to=Console
7
+dependency2.type=UsesDependency
8
+editor.fx.0.height=22
9
+editor.fx.0.width=0
10
+editor.fx.0.x=40
11
+editor.fx.0.y=686
12
+objectbench.height=66
13
+objectbench.width=1256
11 14
 package.divider.horizontal=0.6
12
-package.divider.vertical=0.6847360912981455
13
-package.editor.height=473
14
-package.editor.width=493
15
-package.editor.x=35
16
-package.editor.y=60
17
-package.frame.height=759
18
-package.frame.width=619
19
-package.numDependencies=1
20
-package.numTargets=2
15
+package.divider.vertical=0.9044502617801047
16
+package.editor.height=684
17
+package.editor.width=1154
18
+package.editor.x=0
19
+package.editor.y=0
20
+package.frame.height=800
21
+package.frame.width=1280
22
+package.numDependencies=2
23
+package.numTargets=6
21 24
 package.showExtends=true
22 25
 package.showUses=true
23 26
 project.charset=UTF-8
@@ -27,16 +30,45 @@ readme.width=47
27 30
 readme.x=10
28 31
 readme.y=10
29 32
 target1.height=50
30
-target1.name=Console
33
+target1.name=ScientificFeatures
31 34
 target1.showInterface=false
32 35
 target1.type=ClassTarget
33
-target1.width=80
34
-target1.x=80
35
-target1.y=200
36
+target1.width=140
37
+target1.x=350
38
+target1.y=160
36 39
 target2.height=50
37
-target2.name=MainApplication
40
+target2.name=CoreFeaturesTest
38 41
 target2.showInterface=false
39
-target2.type=ClassTarget
40
-target2.width=120
41
-target2.x=70
42
-target2.y=70
42
+target2.type=UnitTestTargetJunit4
43
+target2.width=110
44
+target2.x=160
45
+target2.y=150
46
+target3.height=50
47
+target3.name=Console
48
+target3.showInterface=false
49
+target3.type=ClassTarget
50
+target3.width=80
51
+target3.x=590
52
+target3.y=10
53
+target4.height=50
54
+target4.name=TrigFeatures
55
+target4.showInterface=false
56
+target4.type=ClassTarget
57
+target4.width=100
58
+target4.x=580
59
+target4.y=160
60
+target5.height=50
61
+target5.name=MainApplication
62
+target5.showInterface=false
63
+target5.type=ClassTarget
64
+target5.width=140
65
+target5.x=350
66
+target5.y=20
67
+target6.association=CoreFeaturesTest
68
+target6.height=50
69
+target6.name=CoreFeatures
70
+target6.showInterface=false
71
+target6.type=ClassTarget
72
+target6.width=110
73
+target6.x=130
74
+target6.y=180