SwitchModes.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Write a description of class SwitchModes here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class SwitchModes
  8. {
  9. // instance variables - replace the example below with your own
  10. private int displayMode=1;
  11. private int unitMode=1;
  12. SwitchModes sm = new SwitchModes();
  13. public int getDisplayMode(){
  14. return displayMode;
  15. }
  16. public void setDisplayMode(int mode){
  17. displayMode=mode;
  18. }
  19. public int getUnitMode(){
  20. return unitMode;
  21. }
  22. public void setUnitMode(int mode){
  23. unitMode=mode;
  24. }
  25. /**
  26. * Constructor for objects of class SwitchModes
  27. */
  28. public SwitchModes()
  29. {
  30. // initialise instance variables
  31. }
  32. /**
  33. * An example of a method - replace this comment with your own
  34. *
  35. * @param y a sample parameter for a method
  36. * @return the sum of x and y
  37. */
  38. public void switchDisplayMode (String mode){
  39. mode.toLowerCase();
  40. switch (mode) {
  41. case "hex": {
  42. displayMode=1;
  43. // call update display
  44. break;
  45. }
  46. case "bin": {
  47. displayMode=2;
  48. // call update display
  49. break;
  50. }
  51. case "dec": {
  52. displayMode=3;
  53. // call update display
  54. break;
  55. }case "oct": {
  56. displayMode=4;
  57. // call update display
  58. break;
  59. }
  60. }
  61. }
  62. public void switchDisplayMode(){
  63. if (displayMode==4){
  64. displayMode=1;
  65. // call update display
  66. }
  67. else {
  68. displayMode++;
  69. // call update display
  70. }
  71. }
  72. public void switchUnitsMode (String mode){
  73. if (mode.toLowerCase()=="degrees") {
  74. unitMode=1;
  75. } else if(mode.toLowerCase()=="radians")
  76. unitMode=2;
  77. }
  78. public void switchUnitsMode(){
  79. if (unitMode==2){
  80. unitMode=1;
  81. // call update display
  82. }
  83. else {
  84. unitMode++;
  85. // call update display
  86. }
  87. }
  88. }