Browse Source

added a random number method

Margaret Pierse 6 years ago
parent
commit
d04fba1a2a
2 changed files with 14 additions and 1 deletions
  1. 8
    1
      Calculator.java
  2. 6
    0
      MathMethods.java

+ 8
- 1
Calculator.java View File

@@ -19,7 +19,7 @@ public static double memory = 0;
19 19
 
20 20
             if (toDo.equals("quit")){
21 21
                 off = true;
22
-                System.out.println("Goodbye!!");
22
+                System.out.println("Goodbye!! \n \n");
23 23
 
24 24
             } else {
25 25
                 switch (toDo) {
@@ -155,6 +155,13 @@ public static double memory = 0;
155 155
                     calc.printAns(calc.switchDisplayMode());
156 156
                     break;
157 157
                     
158
+                    case "random number":
159
+                    result = calc.randomNumber();
160
+                    memory = result;
161
+                    calc.printAns(String.valueOf(result));
162
+                    break;
163
+
164
+                    
158 165
 
159 166
                 }
160 167
             }

+ 6
- 0
MathMethods.java View File

@@ -128,6 +128,12 @@ public class MathMethods
128 128
         }
129 129
         return answer;
130 130
     }
131
+    
132
+    public static double randomNumber() {
133
+    Random rand = new Random();
134
+    return rand.nextDouble()*101;
135
+    
136
+    }
131 137
 
132 138
     public static void printAns(String printAnswer){
133 139
         System.out.println("ANSWER: " + printAnswer + "\n \n");