Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. BankomatModelImpletation
  2.  
  3.  
  4. package at.fhb.iti.algodat.ue2.bankomat.model;
  5.  
  6. import at.fhb.iti.algodat.ue2.bankomat.grafics.BankomatView;
  7.  
  8. import java.nio.channels.CancelledKeyException;
  9.  
  10. import static at.fhb.iti.algodat.ue2.bankomat.model.BankomatState.*;
  11.  
  12. public class BankomatModelImplementation implements BankomatModel {
  13.  
  14. private BankomatView theView;
  15. private BankomatState theState;
  16. private BankomatState from;
  17. private BankomatState to;
  18. private int CorrectCode = 1234;
  19. private int IntDigit = 0;
  20. private int Money = 0;
  21.  
  22. public void setView(BankomatView view) {
  23. theView = view;
  24. theState = START;
  25. }
  26.  
  27. public void pressButtonDigit(int digit) {
  28. from = theState;
  29. switch (theState) {
  30. case ONEDIGIT:
  31. to = TWODIGIT;
  32. IntDigit = digit;
  33. theView.setText(" * ");
  34. System.out.println("Edge 5 from " + from + " to " + to + " via DIGIT");
  35. theState = to;
  36. break;
  37. case TWODIGIT:
  38. to = THREEDIGIT;
  39. IntDigit = IntDigit * 10 + digit;
  40. theView.setText(" * * ");
  41. System.out.println("Edge 8 from " + from + " to " + to + " via DIGIT");
  42. theState = to;
  43. break;
  44. case THREEDIGIT:
  45. to = FOURDIGIT;
  46. IntDigit = IntDigit * 10 + digit;
  47. theView.setText(" * * * ");
  48. System.out.println("Edge 11 from " + from + " to " + to + " via DIGIT");
  49. theState = to;
  50. break;
  51. case FOURDIGIT:
  52. to = CONTROLDIGIT;
  53. IntDigit = IntDigit * 10 + digit;
  54. theView.setText(" * * * * Please press Enter");
  55. System.out.println("Edge 14 from " + from + " to " + to + " via DIGIT");
  56. theState = to;
  57. break;
  58. case CHOOSEMONEY:
  59. Money = Money * 10 + digit;
  60. theState = to;
  61. System.out.println("Edge 18 from " + from + " to " + to + " via DIGIT");
  62. theView.setText("" + Money);
  63. default:
  64. break;
  65. }
  66. }
  67.  
  68. public void pressButtonCancel() {
  69. from = theState;
  70. switch (theState) {
  71. case ONEDIGIT:
  72. cancelMethode();
  73. System.out.println("Edge 3 from " + from + " to " + to + " via CANCEL");
  74. break;
  75. case TWODIGIT:
  76. cancelMethode();
  77. System.out.println("Edge 6 from " + from + " to " + to + " via CANCEL");
  78. break;
  79. case THREEDIGIT:
  80. cancelMethode();
  81. System.out.println("Edge 9 from " + from + " to " + to + " via CANCEL");
  82. break;
  83. case FOURDIGIT:
  84. cancelMethode();
  85. System.out.println("Edge 12 from " + from + " to " + to + " via CANCEL");
  86. break;
  87. case CONTROLDIGIT:
  88. cancelMethode();
  89. System.out.println("Edge 15 from " + from + " to " + to + " via CANCEL");
  90. break;
  91. case CHOOSEMONEY:
  92. cancelMethode();
  93. System.out.println("Edge 21 from " + from + " to " + to + " via CANCEL");
  94. break;
  95. default:
  96. break;
  97. }
  98. }
  99.  
  100. private void cancelMethode() {
  101. to = CANCELCARD;
  102. theView.setText("Cancel pressed.");
  103. theView.setKartenButtonLabel("Take out card.");
  104. theState = to;
  105. }
  106.  
  107. public void pressButtonDelete() {
  108. from = theState;
  109. switch (theState) {
  110. case TWODIGIT:
  111. to = ONEDIGIT;
  112. IntDigit = IntDigit / 10;
  113. theView.setText(" Please enter your code: ");
  114. System.out.println("Edge 4 from " + from + " to " + to + " via DELETE");
  115. theState = to;
  116. break;
  117. case THREEDIGIT:
  118. to = TWODIGIT;
  119. IntDigit = IntDigit / 10;
  120. theView.setText(" * ");
  121. System.out.println("Edge 7 from " + from + " to " + to + " via DELETE");
  122. theState = to;
  123. break;
  124. case FOURDIGIT:
  125. to = THREEDIGIT;
  126. IntDigit = IntDigit / 10;
  127. theView.setText(" * * ");
  128. System.out.println("Edge 10 from " + from + " to " + to + " via DELETE");
  129. theState = to;
  130. break;
  131. case CONTROLDIGIT:
  132. to = FOURDIGIT;
  133. IntDigit = IntDigit / 10;
  134. theView.setText(" * * * ");
  135. System.out.println("Edge 13 from " + from + " to " + to + " via DELETE");
  136. theState = to;
  137. break;
  138. case CHOOSEMONEY:
  139. //to = CHOOSEMONEY;
  140. Money = Money / 10;
  141. System.out.println("Edge 19 from " + from + " to " + to + " via DELETE");
  142. //theState = to;
  143. theView.setText("" + Money);
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149.  
  150. public void pressButtonEnter() {
  151. from = theState;
  152. switch (theState) {
  153. case CONTROLDIGIT:
  154. if (IntDigit == CorrectCode)
  155. {
  156. to = CHOOSEMONEY;
  157. theView.setText("Choose your money amount");
  158. System.out.println("Edge 17 from " + from + " to " + to + " via ENTER");
  159. }
  160. else
  161. {
  162. to = CANCELCARD;
  163. theView.setText("Wrong Code");
  164. theView.setKartenButtonLabel(" Take out card ");
  165. theView.setKartenText(" Please remove card ");
  166. System.out.println("Edge 16 from " + from + " to " + to + " via ENTER");
  167. }
  168. theState = to;
  169.  
  170. break;
  171. case CHOOSEMONEY:
  172. if (Money > 0)
  173. {
  174. to = SUCCESSCARD;
  175. System.out.println("Edge 20 from " + from + " to " + to + " via ENTER");
  176. //theView.setText("Valid entry. Please wait ... ");
  177. theView.setText("Process was successful");
  178. theView.setKartenButtonLabel("Take out card");
  179. theView.setKartenText("Please remove card");
  180. theState = to;
  181. }
  182. else
  183. {
  184. theView.setText("Invalid Input! Please try again.");
  185. }
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191.  
  192. public void pressButtonMoney() {
  193. from = theState;
  194. switch (theState) {
  195. case GETMONEY:
  196. to = START;
  197. theView.setText("Welcome to the ATM!");
  198. //theView.setText("You have receive "+ Money + "€ . Please take your Money");
  199. theView.setGeldladeText(" ");
  200. System.out.println("Edge 23 from " + from + " to " + to + " via MONEY");
  201. theState = to;
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207.  
  208. public void pressButtonCard() {
  209. from = theState;
  210. switch (theState) {
  211. case START:
  212. to = ONEDIGIT;
  213. theView.setText("Please enter code");
  214. theView.setKartenButtonLabel("Card in progress");
  215. theView.setKartenText("Your Card is entered");
  216. System.out.println("Edge 1 from " + from + " to " + to + " via CARD");
  217. theState = to;
  218. break;
  219. case CANCELCARD:
  220. to = START;
  221. theView.setText("Welcome to ATM!");
  222. theView.setKartenButtonLabel(" Insert card ");
  223. theView.setKartenText("Please insert card.");
  224. System.out.println("Edge 2 from " + from + " to " + to + " via CARD");
  225. theState = to;
  226. break;
  227. case SUCCESSCARD:
  228. to = GETMONEY;
  229. theView.setText("Money amount: " + Money + ". ");
  230. theView.setKartenButtonLabel(" Insert Card ");
  231. theView.setGeldladeText("€" + Money );
  232. theView.setKartenText("Card slot is empty");
  233. System.out.println("Edge 22 from " + from + " to " + to + " via CARD");
  234. theState = to;
  235. default:
  236. break;
  237. }
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement