Advertisement
rmword

Untitled

Oct 12th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /**
  2. * @author Rifqi Mukti W
  3. * @version 2017.10.12
  4. */
  5. public class NumberDisplay
  6. {
  7. private int limit;
  8. private int value;
  9.  
  10. /**
  11. * Constructor untuk NumberDisplay
  12. * Set limit dimana display akan berganti dari batas maks ke 08.
  13. */
  14. public NumberDisplay(int rollOverLimit)
  15. {
  16. limit = rollOverLimit;
  17. value = 0;
  18. }
  19.  
  20. /**
  21. * Return value sekarang.
  22. */
  23. public int getValue()
  24. {
  25. return value;
  26. }
  27.  
  28. /**
  29. * Return value display (jika di string kurang dari 10, seperti misal
  30. * 3.5, maka ditambah 0 didepannya menjadi 03.05)
  31. */
  32. public String getDisplayValue()
  33. {
  34. if(value < 10) {
  35. return "0" + value;
  36. }
  37. else {
  38. return "" + value;
  39. }
  40. }
  41.  
  42. /**
  43. * Ubah value di display. Jika value kurang dari 0 atau lebih dari limit,
  44. * tidak dilakukan apa-apa.
  45. */
  46. public void setValue(int replacementValue)
  47. {
  48. if((replacementValue >= 0) && (replacementValue < limit)) {
  49. value = replacementValue;
  50. }
  51. }
  52.  
  53. /**
  54. * Increment satu display value, jika mencapai limit maka menjadi 0
  55. */
  56. public void increment()
  57. {
  58. value = (value + 1) % limit;
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement