Pārlūkot izejas kodu

added afew changes

Roy 6 gadus atpakaļ
vecāks
revīzija
da6f6fcbcb
4 mainītis faili ar 19 papildinājumiem un 49 dzēšanām
  1. 10
    6
      Console.java
  2. 7
    28
      Operations.java
  3. 0
    8
      __SHELL5.java
  4. 2
    7
      scienticFunctions.java

+ 10
- 6
Console.java Parādīt failu

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

+ 7
- 28
Operations.java Parādīt failu

33
 
33
 
34
         Scanner input = new Scanner(System.in);
34
         Scanner input = new Scanner(System.in);
35
         Double result = 0.0;
35
         Double result = 0.0;
36
-        double firstNumber = 0.0;
37
-        double SecondNumber =0.0;
38
         //String userInput = scanner.nextLine();
36
         //String userInput = scanner.nextLine();
39
         scienticFunctions ScientificFunctions = new scienticFunctions();
37
         scienticFunctions ScientificFunctions = new scienticFunctions();
40
         // Calculator calc = new ....
38
         // Calculator calc = new ....
46
                 break;
44
                 break;
47
             }
45
             }
48
             if (command.equalsIgnoreCase("sine"))  {
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
                 Console.printResult(result);
48
                 Console.printResult(result);
59
             }
49
             }
60
             if (command.equalsIgnoreCase("cos"))  {
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
                 Console.printResult(result);
52
                 Console.printResult(result);
66
             }
53
             }
67
             if (command.equalsIgnoreCase("tan"))  {
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
                 Console.printResult(result);
56
                 Console.printResult(result);
72
             }
57
             }
73
             if (command.equalsIgnoreCase("cos-1"))  {
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
                 Console.printResult(result);
60
                 Console.printResult(result);
78
             }
61
             }
79
             if (command.equalsIgnoreCase("sin-1"))  {
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
                 Console.printResult(result);
64
                 Console.printResult(result);
84
             }
65
             }
85
             if (command.equalsIgnoreCase("tan-1"))  {
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
                 Console.printResult(result);
68
                 Console.printResult(result);
90
             }
69
             }
91
-            firstNumber = result;
70
+            //firstNumber = result;
92
             // and on and on
71
             // and on and on
93
         }
72
         }
94
 
73
 

+ 0
- 8
__SHELL5.java Parādīt failu

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 Parādīt failu

27
      * @param  y  a sample parameter for a method
27
      * @param  y  a sample parameter for a method
28
      * @return    the cosine of y
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
      * A method - find the sine of a given number by converting it to radians
33
      * A method - find the sine of a given number by converting it to radians
44
         return Math.sin(Math.toRadians(y));
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
         return Math.cos(Math.toRadians(y));
43
         return Math.cos(Math.toRadians(y));
49
     }
44
     }
50
 
45