Guest User

Untitled

a guest
Oct 23rd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. /* REMEMBER FORMATTING CHECK*/
  7. /* REMEMBER FORMATTING CHECK*/
  8. /* REMEMBER FORMATTING CHECK*/
  9. /* REMEMBER FORMATTING CHECK*/
  10. /* REMEMBER FORMATTING CHECK*/
  11. /* REMEMBER FORMATTING CHECK*/
  12. /* REMEMBER FORMATTING CHECK*/
  13. /* REMEMBER FORMATTING CHECK*/
  14.  
  15. namespace Assessment_1__ATM
  16. {
  17. class ATM
  18. {
  19. const int CHECK_BALANCE = 1;
  20. const int WITHDRAWAL = 2;
  21. const int TRANSFER = 3;
  22. const int SAVINGS_ACCOUNT = 1;
  23. const int DEBIT_CARD = 2;
  24. const int CREDIT_CARD = 3;
  25. const int LINE_OF_CREDIT = 4;
  26. const int EXIT = 0;
  27. const int HIGHEST_INCREMENT = 50;
  28. const int LOWEST_INCREMENT = 20;
  29. const double FEE = 0.1;
  30.  
  31. static double savingsBalance = 901.45;
  32. static double debitCardBalance = 450;
  33. static double creditCardBalance = 1500;
  34. static double lineOfCreditBalance = 2000;
  35.  
  36. static void DisplayMainMenu()
  37. {
  38. {
  39. string menu = "\nWelcome to EziTeller ATM Machine"
  40. + "\n\n\tTransaction Menu"
  41. + "\n\t================"
  42. + "\n\t1. Check Balance"
  43. + "\n\n\t2. Withdrawal"
  44. + "\n\n\t3. Transfer"
  45. + "\n\n\n\n\nPlease enter your choice 1 ... 3 or 0 to Exit:";
  46.  
  47. Console.Write(menu);
  48. }
  49. }
  50.  
  51. static void DisplaySubMenu()
  52. {
  53. {
  54. string menu = "\n\n\t1. Savings Account"
  55. + "\n\n\t2. Debit Card"
  56. + "\n\n\t3. Credit Card"
  57. + "\n\n\t4. Line of Credit"
  58. + "\n\n\n\nPlease enter your choice 1 ... 4 or 0 to Exit:";
  59.  
  60. Console.Write(menu);
  61. }
  62. }
  63.  
  64.  
  65. static int ReadOption(Boolean mainmenu)
  66. {
  67. int lowestValue = 0;
  68. int highestValue = 0;
  69. int option = 0;
  70. bool validMenuOption = false;
  71.  
  72. if (mainmenu == true)
  73. {
  74. lowestValue = CHECK_BALANCE;
  75. highestValue = TRANSFER;
  76. }
  77. else
  78. {
  79. lowestValue = SAVINGS_ACCOUNT;
  80. highestValue = LINE_OF_CREDIT;
  81. }
  82.  
  83. do
  84. {
  85. option = int.Parse(Console.ReadLine());
  86. if ((EXIT <= option) && (option <= highestValue))
  87. {
  88. validMenuOption = true;
  89. }
  90. else {
  91. Console.WriteLine("\n\tOption must be {0} ... {1} or {2} to Exit.",
  92. lowestValue, highestValue, EXIT);
  93. DisplayMainMenu();
  94. }
  95.  
  96. }
  97. while (!validMenuOption);
  98. return option;
  99. }
  100.  
  101. static string SetAccountName(int whichAccount)
  102. {
  103. if (whichAccount == SAVINGS_ACCOUNT) {
  104. return "Savings Account";
  105. }
  106. if (whichAccount == DEBIT_CARD) {
  107. return "Debit Card";
  108. }
  109. if (whichAccount == CREDIT_CARD) {
  110. return "Credit Card";
  111. }
  112. else {
  113. return "Line of Credit";
  114. }
  115. }
  116.  
  117. static double SetBalance(int whichAccount)
  118. {
  119. if (whichAccount == SAVINGS_ACCOUNT) {
  120. return savingsBalance;
  121. }
  122. if (whichAccount == DEBIT_CARD) {
  123. return debitCardBalance;
  124. }
  125. if (whichAccount == CREDIT_CARD) {
  126. return creditCardBalance;
  127. }
  128. else {
  129. return lineOfCreditBalance;
  130. }
  131. }
  132.  
  133. static bool SetFee(int whichAccount)
  134. {
  135. if (whichAccount == CREDIT_CARD || whichAccount == DEBIT_CARD) {
  136. return true;
  137. }
  138. else
  139. {
  140. return false;
  141. }
  142. }
  143.  
  144. static void DisplayBalance(int whichAccount)
  145. {
  146. string accountName = "";
  147. double balance = 0;
  148. DateTime date = DateTime.Now;
  149. Console.WriteLine("\nCurrent Date: {0} ", date);
  150. accountName = SetAccountName(whichAccount);
  151. balance = SetBalance(whichAccount);
  152. Console.WriteLine("\nBalance of {0} is ${1}.", accountName, balance);
  153.  
  154. }
  155.  
  156. static int IncrementalCheck() {
  157. int amount = 0;
  158. while (true) {
  159. Console.WriteLine("Please enter amount:");
  160. amount = int.Parse(Console.ReadLine());
  161. if (amount % HIGHEST_INCREMENT != 0 && amount % 20 != 0) {
  162. Console.WriteLine("Sorry, we cannot dispense {0}.", amount);
  163.  
  164. }
  165. else {
  166. return amount;
  167. }
  168. }
  169. }
  170.  
  171. static void DispenseCash(int amount) {
  172. int withdrawalAmount = amount;
  173. int highestIncrementNotes = 0;
  174. int lowestIncrementNotes = 0;
  175. if ((amount % LOWEST_INCREMENT == 0) && amount % LOWEST_INCREMENT != 0) {
  176. while (amount >= LOWEST_INCREMENT) {
  177. lowestIncrementNotes += 1;
  178. amount = amount - LOWEST_INCREMENT;
  179. }
  180. }
  181. if (amount % HIGHEST_INCREMENT == 0) {
  182. while (amount >= HIGHEST_INCREMENT) {
  183. highestIncrementNotes += 1;
  184. amount = amount - HIGHEST_INCREMENT;
  185. }
  186. }
  187. else {
  188. while ((amount >= HIGHEST_INCREMENT) && (amount % HIGHEST_INCREMENT != 0)) {
  189. amount = amount - HIGHEST_INCREMENT;
  190. highestIncrementNotes += 1;
  191. }
  192. if (amount % LOWEST_INCREMENT == 0) {
  193. while (amount >= LOWEST_INCREMENT) {
  194. amount = amount - LOWEST_INCREMENT;
  195. lowestIncrementNotes += 1;
  196. }
  197. }
  198. }
  199. Console.WriteLine("\nPlease collect ${0} consisting of:", withdrawalAmount);
  200. Console.WriteLine("\n\n\t{0} x ${1} notes", highestIncrementNotes, HIGHEST_INCREMENT);
  201. Console.WriteLine("\t\tand");
  202. Console.WriteLine("\n\n\t{0} x ${1} notes", lowestIncrementNotes, LOWEST_INCREMENT);
  203. }
  204.  
  205.  
  206. static void TransferAmount(int fromAccount, int toAccount) {
  207. }
  208.  
  209. static void WithrawAmount(int whichAccount)
  210. {
  211. int withdrawalAmount = IncrementalCheck();
  212. double balance = SetBalance(whichAccount);
  213. if (SetFee(whichAccount) == false) {
  214. if (balance < withdrawalAmount) {
  215. Console.WriteLine("\nYou have insufficient funds.");
  216. }
  217. else {
  218. if (whichAccount == SAVINGS_ACCOUNT) {
  219. savingsBalance = savingsBalance - withdrawalAmount;
  220. }
  221. if (whichAccount == LINE_OF_CREDIT) {
  222. lineOfCreditBalance = lineOfCreditBalance - withdrawalAmount;
  223. }
  224. DispenseCash(withdrawalAmount);
  225. DisplayBalance(whichAccount);
  226. }
  227. }
  228. else {
  229. if (balance < (withdrawalAmount + FEE)) {
  230. Console.WriteLine("\nYou have insufficient funds.");
  231. }
  232. else {
  233. if (whichAccount == CREDIT_CARD) {
  234. creditCardBalance = creditCardBalance - withdrawalAmount;
  235. }
  236. if (whichAccount == DEBIT_CARD) {
  237. debitCardBalance = debitCardBalance - withdrawalAmount;
  238. }
  239. DispenseCash(withdrawalAmount);
  240. DisplayBalance(whichAccount);
  241. }
  242.  
  243. }
  244. }
  245.  
  246.  
  247. static void Main()
  248. {
  249.  
  250. int transactionOption;
  251. int accountOption;
  252. while (true)
  253. {
  254. DisplayMainMenu();
  255. transactionOption = ReadOption(true);
  256. DisplaySubMenu();
  257. accountOption = ReadOption(false);
  258. if (transactionOption == CHECK_BALANCE)
  259. {
  260. DisplayBalance(accountOption);
  261. }
  262. if (transactionOption == WITHDRAWAL)
  263. {
  264. WithrawAmount(accountOption);
  265. }
  266. if (transactionOption == TRANSFER) {
  267. ReadOption(false);
  268. Console.WriteLine("Transfer from which account?");
  269. TransferAmount();
  270. }
  271. }
  272. }
  273. }
  274. }
Add Comment
Please, Sign In to add comment