12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Write a description of class DiplayMode here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.Scanner;
  8. public class DiplayMode
  9. {
  10. private String currentMode = "decimal";
  11. private double userInput;
  12. public void setResult(double result){
  13. userInput = result;
  14. }
  15. public String enterMode(){
  16. Console.println("Enter mode: decimal, binary, octal, hexadecimal");
  17. Scanner scanner = new Scanner(System.in);
  18. String modeInput = scanner.nextLine();
  19. return modeInput;
  20. }
  21. public void switchDisplayMode(String mode){
  22. this.currentMode = mode;
  23. String value = convertNumber(this.currentMode);
  24. System.out.println(value);
  25. }
  26. public void switchDisplayMode()
  27. {
  28. String[] modes = {"decimal", "binary", "octal", "hexadecimal"};
  29. currentMode = modes[0];
  30. String value = convertNumber(currentMode);
  31. System.out.println(value);
  32. }
  33. public String convertNumber(String command){
  34. String value = "";
  35. if (command.equalsIgnoreCase("decimal")){
  36. value = Double.toString(userInput);
  37. } else if (command.equalsIgnoreCase("binary")){
  38. value = Integer.toBinaryString((int)userInput);
  39. } else if (command.equalsIgnoreCase("octal")){
  40. value = Integer.toOctalString((int)userInput);
  41. } else if (command.equalsIgnoreCase("hexadecimal")){
  42. value = Double.toHexString(userInput);
  43. }
  44. return value;
  45. }
  46. }