Parcourir la source

Finished Core

Arin Turpin il y a 6 ans
Parent
révision
d6141f1f47
2 fichiers modifiés avec 48 ajouts et 11 suppressions
  1. 15
    8
      CoreFeatures.java
  2. 33
    3
      MainApplication.java

+ 15
- 8
CoreFeatures.java Voir le fichier

@@ -18,10 +18,12 @@ public class CoreFeatures extends MainApplication {
18 18
     //divide
19 19
     private double squaredNumber;
20 20
     //square
21
-    private double sqRt;
21
+    private double squareRoot;
22 22
     //square root
23 23
     private boolean calcRunning;
24
-
24
+    //calculator status
25
+    private double invertedNumber;
26
+    //changing the sign of a number
25 27
     /**
26 28
      * Constructor for objects of class CoreFeatures
27 29
      */
@@ -43,7 +45,7 @@ public class CoreFeatures extends MainApplication {
43 45
         return multipliedNumbers;}
44 46
 
45 47
     public double divideNumbers(double dividing1, double dividing2){
46
-        if (dividing2 = 0){
48
+        if (dividing2 == 0){
47 49
             System.out.println("**ERROR** CANNOT DIVIDE BY ZERO.");} else {
48 50
             dividedNumbers = dividing1 / dividing2;
49 51
             return dividedNumbers;}
@@ -53,16 +55,21 @@ public class CoreFeatures extends MainApplication {
53 55
 
54 56
         /*dividedNumbers = dividing1 / dividing2;
55 57
         return dividedNumbers;*/
56
-    }
58
+    return dividedNumbers;}
57 59
 
58 60
     public double squareNumber(double squaring){
59 61
         squaredNumber = squaring * squaring;
60 62
         return squaredNumber;}
61 63
 
62
-    public double squareRoot(double sqRting){
63
-        sqRt = squareRoot(sqRting);
64
-        return sqRt;}
65
-
64
+    public double squareRoot(double squareRooting){
65
+        squareRoot = squareRoot(squareRooting);
66
+        return squareRoot;}
67
+    
68
+    public double invertSign(double inverting){
69
+        invertedNumber = inverting * -1;
70
+        return invertedNumber;
71
+    }
72
+        
66 73
     public boolean calcRunning(){
67 74
         calcRunning = false;
68 75
         return calcRunning;

+ 33
- 3
MainApplication.java Voir le fichier

@@ -9,9 +9,15 @@ public class MainApplication {
9 9
         CoreFeatures switchCoreFeatures = new CoreFeatures();
10 10
         
11 11
         //User instructions 
12
-       String userInput = Console.getStringInput("Choose a symbol for the corresponding function : " + "\n"
13
-       + " |'+' = addition|" + "\n"+
14
-       "|'-' = subtraction|");
12
+       String userInput = Console.getStringInput("Choose a symbol for the corresponding function: " + "\n"+ 
13
+       "'+' = addition \n"+
14
+       "'-' = subtraction \n" +
15
+       "'*' = multiplication \n" +
16
+       "'/' = division \n" +
17
+       "'^' = square \n" +
18
+       "'^/' = square root \n" +
19
+       "'-/' = invert sign \n" +
20
+       "'off' = turns calculator off \n\n");
15 21
         
16 22
     switch(userInput){
17 23
     case "+": 
@@ -32,6 +38,30 @@ public class MainApplication {
32 38
     System.out.println(Console.result);
33 39
     break;
34 40
     
41
+    case "/":
42
+    double userInput5 = Console.getDoubleInput("Enter number to be multiplied. ");
43
+    Console.result = switchCoreFeatures.multiplyNumbers(Console.result, userInput5);
44
+    System.out.println(Console.result);
45
+    break;
46
+    
47
+    case "^":
48
+    double userInput6 = Console.getDoubleInput("Enter number to be squared. ");
49
+    Console.result = switchCoreFeatures.squareNumber(userInput6);
50
+    System.out.println(Console.result);
51
+    break;
52
+    
53
+    case "^/":
54
+    double userInput7 = Console.getDoubleInput("Enter number to be squared rooted. ");
55
+    Console.result = switchCoreFeatures.squareRoot(userInput7);
56
+    System.out.println(Console.result);
57
+    break;
58
+    
59
+    case "-/":
60
+    double userInput8 = Console.getDoubleInput("Enter number to be inverted. ");
61
+    Console.result = switchCoreFeatures.invertSign(userInput8);
62
+    System.out.println(Console.result);
63
+    break;
64
+    
35 65
     case "off":
36 66
     Console.calcRunning = false;
37 67
     break;