Browse Source

added more changes

Roy 6 years ago
parent
commit
e82b1b19eb
5 changed files with 114 additions and 40 deletions
  1. 57
    0
      DiplayMode.java
  2. 1
    1
      MainApplication.java
  3. 34
    0
      Memory.java
  4. 21
    18
      Operations.java
  5. 1
    21
      scienticFunctions.java

+ 57
- 0
DiplayMode.java View File

@@ -0,0 +1,57 @@
1
+
2
+/**
3
+ * Write a description of class DiplayMode here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+import java.util.Scanner;
9
+public class DiplayMode
10
+{
11
+
12
+    private String currentMode = "decimal";
13
+    private double userInput;
14
+
15
+    public void setResult(double result){
16
+        userInput = result;
17
+    }
18
+    
19
+    public String enterMode(){
20
+        Console.println("Enter mode: decimal, binary, octal, hexadecimal");
21
+        Scanner scanner = new Scanner(System.in);
22
+        String modeInput = scanner.nextLine();
23
+        return modeInput;
24
+        
25
+    }
26
+
27
+    public void switchDisplayMode(String mode){
28
+        this.currentMode = mode;
29
+        String value = convertNumber(this.currentMode);
30
+        System.out.println(value);
31
+    }
32
+
33
+    public void switchDisplayMode()
34
+    {  
35
+        String[] modes = {"decimal", "binary", "octal", "hexadecimal"};
36
+        currentMode = modes[0];
37
+        String value = convertNumber(currentMode);
38
+        System.out.println(value);
39
+
40
+    }
41
+
42
+    public String convertNumber(String command){
43
+        String value = "";
44
+        if (command.equalsIgnoreCase("decimal")){
45
+            value = Double.toString(userInput);
46
+        } else if (command.equalsIgnoreCase("binary")){
47
+            value = Integer.toBinaryString((int)userInput);
48
+        } else if (command.equalsIgnoreCase("octal")){
49
+            value = Integer.toOctalString((int)userInput);
50
+        } else if (command.equalsIgnoreCase("hexadecimal")){
51
+            value = Double.toHexString(userInput);
52
+        }
53
+        return value;
54
+    }
55
+
56
+}
57
+

+ 1
- 1
MainApplication.java View File

@@ -1,6 +1,6 @@
1 1
 
2 2
 /**
3
- * Created by leon on 2/9/18.
3
+ * Created by Roy Mpanju on 5/29/18.
4 4
  */
5 5
 public class MainApplication {
6 6
     //Operations Operations = new Operations();

+ 34
- 0
Memory.java View File

@@ -0,0 +1,34 @@
1
+
2
+/**
3
+ * Write a description of class Memory here.
4
+ *
5
+ * @author (Roy Mpanju)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Memory extends Operations
9
+{
10
+    Double numberInMemory = 0.0;
11
+    
12
+    /**
13
+     * An example of a method - replace this comment with your own
14
+     *
15
+     * @param  y  a sample parameter for a method
16
+     * @return    the sum of x and y
17
+     */
18
+    public Double storeInMemory(Double currentDisplay)
19
+    {
20
+        // put your code here
21
+        numberInMemory = currentDisplay;
22
+        return numberInMemory;
23
+    }
24
+    
25
+    public Double clearMemory(){
26
+        return numberInMemory = 0.0;
27
+    }
28
+    
29
+    public Double retrieveFromMemory(){
30
+        return numberInMemory;
31
+    }
32
+    
33
+    //public String 
34
+}

+ 21
- 18
Operations.java View File

@@ -8,26 +8,10 @@
8 8
 import java.util.Scanner;
9 9
 public class Operations
10 10
 {
11
-    // instance variables - replace the example below with your own
12
-    private int x;
13
-    scienticFunctions scientificOperator = new scienticFunctions();
14
-
15
-    /**
16
-     * Constructor for objects of class Operations
17
-     */
18
-    public Operations()
19
-    {
20
-        // initialise instance variables
21
-        //x = 0;
22
-    }
23
-
24 11
     /**
25
-     * An example of a method - replace this comment with your own
26
-     *
27
-     * @param  y  a sample parameter for a method
28
-     * @return    the sum of x and y
12
+     * prompting a user for a command solving for that command
29 13
      */
30
-    public static void runCommand()
14
+    public static Double runCommand()
31 15
     {
32 16
         // put your code here
33 17
 
@@ -35,6 +19,8 @@ public class Operations
35 19
         Double result = 0.0;
36 20
         //String userInput = scanner.nextLine();
37 21
         scienticFunctions ScientificFunctions = new scienticFunctions();
22
+        Memory memory = new Memory();
23
+        DiplayMode displayMode = new DiplayMode();
38 24
         // Calculator calc = new ....
39 25
         while (true) {
40 26
             System.out.print("Enter a command: ");
@@ -67,9 +53,26 @@ public class Operations
67 53
                 result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number"));
68 54
                 Console.printResult(result);
69 55
             }
56
+            if(command.equalsIgnoreCase("m+")){
57
+                memory.storeInMemory(result);
58
+                Console.printResult(result);
59
+            }
60
+            
61
+            if (command.equalsIgnoreCase("m-")){
62
+                Console.printResult(memory.retrieveFromMemory());
63
+            }
64
+            
65
+            if (command.equalsIgnoreCase("switchmode")){
66
+                displayMode.setResult(result);
67
+                String mode = displayMode.enterMode();
68
+                //System.out.println(mode);
69
+                displayMode.switchDisplayMode(mode);
70
+                
71
+            }
70 72
             //firstNumber = result;
71 73
             // and on and on
72 74
         }
75
+        return result;
73 76
 
74 77
     }
75 78
 

+ 1
- 21
scienticFunctions.java View File

@@ -9,28 +9,8 @@
9 9
 import java.lang.*;
10 10
 public class scienticFunctions
11 11
 {
12
-    // instance variables - replace the example below with your own
13
-    //private int x;
14
-
15
-    /**
16
-     * Constructor for objects of class scienticFunctions
17
-     */
18
-    // public scienticFunctions()
19
-    // {
20
-    // // initialise instance variables
21
-    // x = 0;
22
-    // }
23
-
24
-    /**
25
-     * A method - find the cosine of a given number
26
-     *
27
-     * @param  y  a sample parameter for a method
28
-     * @return    the cosine of y
29
-     */
30
-    
31
-
32 12
     /**
33
-     * A method - find the sine of a given number by converting it to radians
13
+     * A method - find solve for the trignometry functions of a given number by converting it to radians
34 14
      *
35 15
      * @param  y  a sample parameter for a method
36 16
      * @return    the sine of y