|
@@ -34,37 +34,41 @@ public class SwitchDisplay
|
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: " + toBinary(baseInput)
|
38
|
|
- + "\nOctal: " + toOctal(baseInput)
|
39
|
|
- + "\nDecimal: " + baseInput
|
40
|
|
- + "\nHexadecimal: " + toHexa(baseInput)
|
|
37
|
+ + "\nBinary"
|
|
38
|
+ + "\nOctal"
|
|
39
|
+ + "\nDecimal"
|
|
40
|
+ + "\nHexadecimal"
|
41
|
41
|
+ "\nCancel: returns to Main Menu");
|
|
42
|
+ // Accepts next input to display mode.
|
|
43
|
+ mode = Console.getStringInput("Enter the base option to display.").toLowerCase();
|
42
|
44
|
|
43
|
|
- mode = Console.getStringInput("Enter the base option to display.");
|
44
|
|
- if (mode.toLowerCase().equals("binary") == true) {
|
45
|
|
-
|
46
|
|
- } else if (mode.toLowerCase().equals("octal") == true) {
|
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
|
|
-
|
|
45
|
+ if (mode.equals("binary") == true) {
|
|
46
|
+ Console.println(baseInput + "in binary: " + toBinary(baseInput));
|
|
47
|
+ } else if (mode.equals("octal") == true) {
|
|
48
|
+ Console.println(baseInput + "in octal: " + toOctal(baseInput));
|
|
49
|
+ } else if (mode.equals("decimal") == true) {
|
|
50
|
+ Console.println(baseInput + "in decimal: " + baseInput);
|
|
51
|
+ } else if (mode.equals("hexadecimal") == true) {
|
|
52
|
+ Console.println(baseInput + "in hexadecimal: " + toHexa(baseInput));
|
|
53
|
+ } else if (mode.equals("cancel") == true) {
|
|
54
|
+ Console.println("Returning to Main Menu");
|
|
55
|
+ // calls back to main application menu
|
54
|
56
|
} else {
|
55
|
57
|
Console.println("Invalid input.");
|
56
|
58
|
}
|
|
59
|
+
|
57
|
60
|
}
|
58
|
61
|
|
|
62
|
+ /**
|
|
63
|
+ * Converts the user input into corresponding base types
|
|
64
|
+ */
|
|
65
|
+
|
59
|
66
|
public String toBinary(int userInput) {
|
60
|
67
|
|
61
|
68
|
return Integer.toBinaryString(userInput);
|
62
|
69
|
|
63
|
70
|
}
|
64
|
71
|
|
65
|
|
- /**
|
66
|
|
- * Converts the user input into octal and returns a string of that octal.
|
67
|
|
- */
|
68
|
72
|
public String toOctal(int userInput) {
|
69
|
73
|
|
70
|
74
|
return Integer.toOctalString(userInput);
|