DisplayMode.java 997B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Write a description of class Conversion here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class DisplayMode
  8. {
  9. enum Mode {
  10. Binary,
  11. Octal,
  12. Decimal,
  13. Hexadecimal
  14. }
  15. String switchedValue = new String();
  16. public String switchDisplayMode(Mode mode, String displayValue) {
  17. switch (mode) {
  18. case Binary:
  19. switchedValue = Long.toBinaryString(Double.doubleToLongBits(Double.parseDouble(displayValue)));
  20. break;
  21. case Octal:
  22. switchedValue = Long.toOctalString(Double.doubleToLongBits(Double.parseDouble(displayValue)));
  23. break;
  24. case Decimal:
  25. switchedValue = displayValue;
  26. break;
  27. case Hexadecimal:
  28. switchedValue = Double.toHexString(Double.parseDouble(displayValue));
  29. break;
  30. }
  31. return switchedValue;
  32. }
  33. }