浏览代码

Updated Switch Display methods

Trinh Tong 6 年前
父节点
当前提交
03ea527c54
共有 1 个文件被更改,包括 31 次插入7 次删除
  1. 31
    7
      SwitchDisplay.java

+ 31
- 7
SwitchDisplay.java 查看文件

@@ -32,22 +32,34 @@ public class SwitchDisplay
32 32
     public void switchDisplay(String mode)
33 33
     {
34 34
         int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
35
-        
35
+        // try catch for int vs double or other input
36 36
         Console.println("Display Options" 
37
-                         + "\nBinary: " + null
38
-                         + "\nOctal: " + null
39
-                         + "\nDecimal: " + null
40
-                         + "\nHexadecimal: " + null
41
-                         + "\n");
37
+                         + "\nBinary: " + toBinary(baseInput)
38
+                         + "\nOctal: " + toOctal(baseInput)
39
+                         + "\nDecimal: " + baseInput
40
+                         + "\nHexadecimal: " + toHexa(baseInput)
41
+                         + "\nCancel: returns to Main Menu");
42 42
         
43 43
         mode = Console.getStringInput("Enter the base option to display.");
44 44
         if (mode.toLowerCase().equals("binary") == true) {
45 45
             
46 46
         } else if (mode.toLowerCase().equals("octal") == true) {
47 47
             
48
+        } else if (mode.toLowerCase().equals("decimal") == true) {
49
+            
50
+        } else if (mode.toLowerCase().equals("hexadecimal") == true) {
51
+            
52
+        } else if (mode.toLowerCase().equals("cancel") == true) {
53
+            
54
+        } else {
55
+            Console.println("Invalid input.");
48 56
         }
57
+    }
58
+    
59
+    public String toBinary(int userInput) {
60
+        
61
+        return Integer.toBinaryString(userInput);
49 62
         
50
-
51 63
     }
52 64
     
53 65
     /**
@@ -58,4 +70,16 @@ public class SwitchDisplay
58 70
         return Integer.toOctalString(userInput);
59 71
         
60 72
     }
73
+    
74
+    public String toDecimal(int userInput) {
75
+        
76
+        return Integer.toBinaryString(userInput);
77
+        
78
+    }
79
+    
80
+    public String toHexa(int userInput) {
81
+    
82
+        return Integer.toHexString(userInput);
83
+    
84
+    }
61 85
 }