Bläddra i källkod

added afew changes

Roy 6 år sedan
förälder
incheckning
da6f6fcbcb
4 ändrade filer med 19 tillägg och 49 borttagningar
  1. 10
    6
      Console.java
  2. 7
    28
      Operations.java
  3. 0
    8
      __SHELL5.java
  4. 2
    7
      scienticFunctions.java

+ 10
- 6
Console.java Visa fil

@@ -1,7 +1,5 @@
1
- 
2 1
 
3 2
 import java.util.Scanner;
4
-
5 3
 /**
6 4
  * Created by leon on 2/9/18.
7 5
  */
@@ -14,8 +12,9 @@ public class Console {
14 12
     public static void println(String output, Object... args) {
15 13
         print(output + "\n", args);
16 14
     }
15
+
17 16
     public static void printResult(Double result) {
18
-        System.out.println(result);
17
+        System.out.println("Result = " + result);
19 18
     }
20 19
 
21 20
     public static String getStringInput(String prompt) {
@@ -26,10 +25,10 @@ public class Console {
26 25
     }
27 26
 
28 27
     public static Integer getIntegerInput(String prompt) {
29
-        Scanner scanner = new Scanner(System.in);
28
+        Scanner scanner_1 = new Scanner(System.in);
30 29
         println(prompt);
31
-        Integer userInput = scanner.nextInt();
32
-        return userInput;
30
+        Integer firstNumber = scanner_1.nextInt();
31
+        return firstNumber;
33 32
     }
34 33
 
35 34
     public static Double getDoubleInput(String prompt) {
@@ -38,4 +37,9 @@ public class Console {
38 37
         Double userInput = scanner.nextDouble();
39 38
         return userInput;
40 39
     }
40
+
41
+    //public static Double getNumberForUniOperators(){
42
+        
43
+
44
+   // }
41 45
 }

+ 7
- 28
Operations.java Visa fil

@@ -33,8 +33,6 @@ public class Operations
33 33
 
34 34
         Scanner input = new Scanner(System.in);
35 35
         Double result = 0.0;
36
-        double firstNumber = 0.0;
37
-        double SecondNumber =0.0;
38 36
         //String userInput = scanner.nextLine();
39 37
         scienticFunctions ScientificFunctions = new scienticFunctions();
40 38
         // Calculator calc = new ....
@@ -46,49 +44,30 @@ public class Operations
46 44
                 break;
47 45
             }
48 46
             if (command.equalsIgnoreCase("sine"))  {
49
-                // read first number
50
-                System.out.print("Enter a number: ");
51
-                firstNumber = input.nextDouble();
52
-                // read second number
53
-                //double secondNumber = input.nextDouble();
54
-                // call the add method on calc and display
55
-                result  = ScientificFunctions.sine(firstNumber);
56
-                //firstNumber = result;
57
-                //result = firstNumber;
47
+                result = ScientificFunctions.sine(Console.getDoubleInput("Enter number"));
58 48
                 Console.printResult(result);
59 49
             }
60 50
             if (command.equalsIgnoreCase("cos"))  {
61
-                // read first number
62
-                firstNumber = input.nextDouble();
63
-                // call the cosine method on calc and display
64
-                result  = ScientificFunctions.cos(firstNumber);
51
+                result = ScientificFunctions.cosine(Console.getDoubleInput("Enter number"));
65 52
                 Console.printResult(result);
66 53
             }
67 54
             if (command.equalsIgnoreCase("tan"))  {
68
-            // call the square method on calc and display
69
-                firstNumber = input.nextDouble();
70
-                result = ScientificFunctions.tangent(firstNumber);
55
+                result = ScientificFunctions.tangent(Console.getDoubleInput("Enter number"));
71 56
                 Console.printResult(result);
72 57
             }
73 58
             if (command.equalsIgnoreCase("cos-1"))  {
74
-            // call the square method on calc and display
75
-                firstNumber = input.nextDouble();
76
-                result = ScientificFunctions.inverseCosine(firstNumber);
59
+                result = ScientificFunctions.inverseCosine(Console.getDoubleInput("Enter number"));
77 60
                 Console.printResult(result);
78 61
             }
79 62
             if (command.equalsIgnoreCase("sin-1"))  {
80
-            // call the square method on calc and display
81
-                firstNumber = input.nextDouble();
82
-                result = ScientificFunctions.inverseSine(firstNumber);
63
+                result = ScientificFunctions.inverseSine(Console.getDoubleInput("Enter number"));
83 64
                 Console.printResult(result);
84 65
             }
85 66
             if (command.equalsIgnoreCase("tan-1"))  {
86
-            // call the square method on calc and display
87
-                firstNumber = input.nextDouble();
88
-                result = ScientificFunctions.inverseTangent(firstNumber);
67
+                result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number"));
89 68
                 Console.printResult(result);
90 69
             }
91
-            firstNumber = result;
70
+            //firstNumber = result;
92 71
             // and on and on
93 72
         }
94 73
 

+ 0
- 8
__SHELL5.java Visa fil

@@ -1,8 +0,0 @@
1
-
2
-public class __SHELL5 extends bluej.runtime.Shell {
3
-public static void run() throws Throwable {
4
-
5
-java.lang.String[] __bluej_param0 = { };
6
-MainApplication.main(__bluej_param0);
7
-
8
-}}

+ 2
- 7
scienticFunctions.java Visa fil

@@ -27,12 +27,7 @@ public class scienticFunctions
27 27
      * @param  y  a sample parameter for a method
28 28
      * @return    the cosine of y
29 29
      */
30
-    public double cosine(double y)
31
-    {
32
-        double x = Math.toRadians(y);
33
-
34
-        return Math.cos(x);
35
-    }
30
+    
36 31
 
37 32
     /**
38 33
      * A method - find the sine of a given number by converting it to radians
@@ -44,7 +39,7 @@ public class scienticFunctions
44 39
         return Math.sin(Math.toRadians(y));
45 40
     }
46 41
     
47
-    public static double cos(double y){
42
+    public static double cosine(double y){
48 43
         return Math.cos(Math.toRadians(y));
49 44
     }
50 45