|
@@ -32,32 +32,46 @@ public class SwitchDisplay
|
32
|
32
|
|
33
|
33
|
public void switchDisplay()
|
34
|
34
|
{
|
35
|
|
- int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
|
36
|
|
- // try catch for int vs double or other input
|
37
|
|
- Console.println("Display Options"
|
38
|
|
- + "\nBinary"
|
39
|
|
- + "\nOctal"
|
40
|
|
- + "\nDecimal"
|
41
|
|
- + "\nHexadecimal"
|
42
|
|
- + "\nCancel: returns to Main Menu");
|
43
|
|
- // Accepts next input to display mode.
|
44
|
|
- String mode = Console.getStringInput("Enter the base option to display.").toLowerCase();
|
45
|
|
-
|
46
|
|
- if (mode.equals("binary") == true) {
|
47
|
|
- Console.println(baseInput + "in binary: " + toBinary(baseInput));
|
48
|
|
- } else if (mode.equals("octal") == true) {
|
49
|
|
- Console.println(baseInput + "in octal: " + toOctal(baseInput));
|
50
|
|
- } else if (mode.equals("decimal") == true) {
|
51
|
|
- Console.println(baseInput + "in decimal: " + baseInput);
|
52
|
|
- } else if (mode.equals("hexadecimal") == true) {
|
53
|
|
- Console.println(baseInput + "in hexadecimal: " + toHexa(baseInput));
|
54
|
|
- } else if (mode.equals("cancel") == true) {
|
55
|
|
- Console.println("Returning to Main Menu");
|
56
|
|
- // calls back to main application menu
|
57
|
|
- } else {
|
58
|
|
- Console.println("Invalid input.");
|
|
35
|
+ String mode = "";
|
|
36
|
+ while (!mode.equals("cancel")) {
|
|
37
|
+ int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions.");
|
|
38
|
+
|
|
39
|
+ Console.println("Display Options"
|
|
40
|
+ + "\nBinary"
|
|
41
|
+ + "\nOctal"
|
|
42
|
+ + "\nDecimal"
|
|
43
|
+ + "\nHexadecimal"
|
|
44
|
+ + "\nCancel: returns to Main Menu");
|
|
45
|
+ // Asks for the mode
|
|
46
|
+ mode = Console.getStringInput("Enter the desired display mode: ");
|
|
47
|
+
|
|
48
|
+ String convertedInput = switchDisplayOutput(mode, baseInput);
|
|
49
|
+
|
|
50
|
+ Console.println(convertedInput);
|
|
51
|
+ // passes to switchDisplayOutput(mode) >> returns string
|
|
52
|
+ // displays the returned string
|
|
53
|
+ // while loops !cancel
|
59
|
54
|
}
|
60
|
|
-
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ public String switchDisplayOutput(String mode, int baseInput) {
|
|
59
|
+ switch (mode) {
|
|
60
|
+ case "binary":
|
|
61
|
+ return toBinary(baseInput);
|
|
62
|
+
|
|
63
|
+ case "octal":
|
|
64
|
+ return toOctal(baseInput);
|
|
65
|
+
|
|
66
|
+ case "decimal":
|
|
67
|
+ return toDecimal(baseInput);
|
|
68
|
+
|
|
69
|
+ case "hexadecimal":
|
|
70
|
+ return toHexa(baseInput);
|
|
71
|
+
|
|
72
|
+ default:
|
|
73
|
+ return "Invalid Input";
|
|
74
|
+ }
|
61
|
75
|
}
|
62
|
76
|
|
63
|
77
|
/**
|