/** * Write a description of class SwitchDisplay here. * * Scientific Calculator Lab * * Brings up the switch display menu * Binary * Octal * Decimal * Hexadecimal * * Changes the mode for EVERYTHING * * Find a way to store the input and the input as a diff base * then whenever the base is changed, display the base. * pass the input into the methods to return the string. * EVERY TIME AN INPUT IS PLACED, IT WILL BE DISPLAYED AS AN OCTAL * boolean baseChange == true; * display the changed display */ public class SwitchDisplay { // instance variables - replace the example below with your own /** * Switch Display Mode method * -> binary, octal, decimal, hexadecimal * switchDisplayMode() rotates through the options * switchDisplayMode(String mode) sets the display to the mode given */ public void switchDisplay() { String mode = "Invalid Input"; while (mode.equals("Invalid Input")) { int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions."); Console.println("Display Options" + "\n1: Binary" + "\n2: Octal" + "\n3: Decimal" + "\n4: Hexadecimal" + "\n5: Cancel - returns to Main Menu"); // Asks for the mode mode = Console.getStringInput("Enter the desired display mode: "); String convertedInput = switchDisplayOutput(mode, baseInput); Console.println(convertedInput); // passes to switchDisplayOutput(mode) >> returns string // displays the returned string // while loops !cancel } } public String switchDisplayOutput(String mode, int baseInput) { switch (mode) { case "1": return toBinary(baseInput); case "2": return toOctal(baseInput); case "3": return toDecimal(baseInput); case "4": return toHexa(baseInput); case "5": return mode; default: return "Invalid Input"; } } /** * Converts the user input into corresponding base types */ public String toBinary(int userInput) { return Integer.toBinaryString(userInput); } public String toOctal(int userInput) { return Integer.toOctalString(userInput); } public String toDecimal(int userInput) { return Integer.toBinaryString(userInput); } public String toHexa(int userInput) { return Integer.toHexString(userInput); } }