Guest User

Untitled

a guest
Apr 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. import components.naturalnumber.NaturalNumber;
  2. import components.naturalnumber.NaturalNumber2;
  3.  
  4. /**
  5. * Controller class.
  6. *
  7. * @author Put your name here
  8. */
  9. public final class NNCalcController1 implements NNCalcController {
  10.  
  11. /**
  12. * Model object.
  13. */
  14. private final NNCalcModel model;
  15.  
  16. /**
  17. * View object.
  18. */
  19. private final NNCalcView view;
  20.  
  21. /**
  22. * Useful constants.
  23. */
  24. private static final NaturalNumber TWO = new NaturalNumber2(2),
  25. INT_LIMIT = new NaturalNumber2(Integer.MAX_VALUE);
  26.  
  27. /**
  28. * Updates this.view to display this.model, and to allow only operations
  29. * that are legal given this.model.
  30. *
  31. * @param model
  32. * the model
  33. * @param view
  34. * the view
  35. * @ensures [view has been updated to be consistent with model]
  36. */
  37. private static void updateViewToMatchModel(NNCalcModel model,
  38. NNCalcView view) {
  39.  
  40. }
  41.  
  42. /**
  43. * Constructor.
  44. *
  45. * @param model
  46. * model to connect to
  47. * @param view
  48. * view to connect to
  49. */
  50. public NNCalcController1(NNCalcModel model, NNCalcView view) {
  51. this.model = model;
  52. this.view = view;
  53. updateViewToMatchModel(model, view);
  54. }
  55.  
  56. @Override
  57. public void processClearEvent() {
  58. /*
  59. * Get alias to bottom from model
  60. */
  61. NaturalNumber bottom = this.model.bottom();
  62. /*
  63. * Update model in response to this event
  64. */
  65. bottom.clear();
  66. /*
  67. * Update view to reflect changes in model
  68. */
  69. updateViewToMatchModel(this.model, this.view);
  70. }
  71.  
  72. @Override
  73. public void processSwapEvent() {
  74. /*
  75. * Get aliases to top and bottom from model
  76. */
  77. NaturalNumber top = this.model.top();
  78. NaturalNumber bottom = this.model.bottom();
  79. /*
  80. * Update model in response to this event
  81. */
  82. NaturalNumber temp = top.newInstance();
  83. temp.transferFrom(top);
  84. top.transferFrom(bottom);
  85. bottom.transferFrom(temp);
  86. /*
  87. * Update view to reflect changes in model
  88. */
  89. updateViewToMatchModel(this.model, this.view);
  90. }
  91.  
  92. @Override
  93. public void processEnterEvent() {
  94.  
  95. // TODO: fill in body
  96.  
  97. }
  98.  
  99. @Override
  100. public void processAddEvent() {
  101.  
  102. // TODO: fill in body
  103.  
  104. }
  105.  
  106. @Override
  107. public void processSubtractEvent() {
  108.  
  109. // TODO: fill in body
  110.  
  111. }
  112.  
  113. @Override
  114. public void processMultiplyEvent() {
  115.  
  116. // TODO: fill in body
  117.  
  118. }
  119.  
  120. @Override
  121. public void processDivideEvent() {
  122.  
  123. // TODO: fill in body
  124.  
  125. }
  126.  
  127. @Override
  128. public void processPowerEvent() {
  129.  
  130. // TODO: fill in body
  131.  
  132. }
  133.  
  134. @Override
  135. public void processRootEvent() {
  136.  
  137. // TODO: fill in body
  138.  
  139. }
  140.  
  141. @Override
  142. public void processAddNewDigitEvent(int digit) {
  143.  
  144. // TODO: fill in body
  145.  
  146. }
  147.  
  148. }
Add Comment
Please, Sign In to add comment