SwitchDisplay.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Write a description of class SwitchDisplay here.
  3. *
  4. * Scientific Calculator Lab
  5. *
  6. * Brings up the switch display menu
  7. * Binary
  8. * Octal
  9. * Decimal
  10. * Hexadecimal
  11. *
  12. * Changes the mode for EVERYTHING
  13. *
  14. * Find a way to store the input and the input as a diff base
  15. * then whenever the base is changed, display the base.
  16. * pass the input into the methods to return the string.
  17. * EVERY TIME AN INPUT IS PLACED, IT WILL BE DISPLAYED AS AN OCTAL
  18. * boolean baseChange == true;
  19. * display the changed display
  20. */
  21. public class SwitchDisplay
  22. {
  23. // instance variables - replace the example below with your own
  24. /**
  25. * Switch Display Mode method
  26. * -> binary, octal, decimal, hexadecimal
  27. * switchDisplayMode() rotates through the options
  28. * switchDisplayMode(String mode) sets the display to the mode given
  29. */
  30. public void switchDisplay()
  31. {
  32. Console.println("Display Options"
  33. + "\n1: Binary"
  34. + "\n2: Octal"
  35. + "\n3: Decimal"
  36. + "\n4: Hexadecimal"
  37. + "\n5: Cancel - returns to Main Menu");
  38. }
  39. /**
  40. * Converts the user input into corresponding base types
  41. */
  42. public String toBinary(double userInput) {
  43. return Integer.toBinaryString((int)userInput);
  44. }
  45. public String toOctal(double userInput) {
  46. return Integer.toOctalString((int)userInput);
  47. }
  48. public String toDecimal(int userInput) {
  49. return Integer.toString(userInput);
  50. }
  51. public String toHexa(int userInput) {
  52. return Integer.toHexString((int)userInput);
  53. }
  54. }