12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
-
- /**
- * 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()
- {
- Console.println("Display Options"
- + "\n1: Binary"
- + "\n2: Octal"
- + "\n3: Decimal"
- + "\n4: Hexadecimal"
- + "\n5: Cancel - returns to Main Menu");
-
- }
-
- 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);
-
- }
- }
|