/** * 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() { int baseInput = Console.getIntegerInput("Enter an integer to see the base conversions."); // try catch for int vs double or other input Console.println("Display Options" + "\nBinary" + "\nOctal" + "\nDecimal" + "\nHexadecimal" + "\nCancel: returns to Main Menu"); // Accepts next input to display mode. String mode = Console.getStringInput("Enter the base option to display.").toLowerCase(); if (mode.equals("binary") == true) { Console.println(baseInput + "in binary: " + toBinary(baseInput)); } else if (mode.equals("octal") == true) { Console.println(baseInput + "in octal: " + toOctal(baseInput)); } else if (mode.equals("decimal") == true) { Console.println(baseInput + "in decimal: " + baseInput); } else if (mode.equals("hexadecimal") == true) { Console.println(baseInput + "in hexadecimal: " + toHexa(baseInput)); } else if (mode.equals("cancel") == true) { Console.println("Returning to Main Menu"); // calls back to main application menu } else { Console.println("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); } }