Advertisement
wis3_guy

ATM Simulator

Mar 7th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace atm_program
  7. {
  8. public class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string screen;
  13. int menupick = -1;
  14. Account myAccount = null;
  15.  
  16. while (myAccount == null)
  17. {
  18. Console.WriteLine("Welcome to the Bank");
  19. Console.WriteLine("Please Select an Operation");
  20. Console.WriteLine("1. Deposit");
  21. Console.WriteLine("2. Withdraw");
  22. screen = Console.ReadLine();
  23. if(int.TryParse(screen, out menupick))
  24. {
  25. if (menupick == 1)
  26. myAccount = new Deposit();
  27. else if (menupick == 2)
  28. myAccount = new Withdrawal();
  29. else
  30. Console.WriteLine("Error: Invalid Operation");
  31.  
  32. }
  33. else
  34. {
  35. Console.WriteLine("You must select an operation to proceed.");
  36. }
  37. }
  38.  
  39. while (menupick != 0)
  40. {
  41. Console.WriteLine();
  42. Console.WriteLine("1. Account Status");
  43. Console.WriteLine("2. Make Deposit");
  44. Console.WriteLine("3. Make Withdrawal");
  45. //Console.WriteLine("4. View Savings Balance");
  46. // Console.WriteLine("5. View Checking Balance");
  47. Console.WriteLine("0. Quit");
  48. Console.WriteLine();
  49. Console.Write("Enter Command: ");
  50. screen = Console.ReadLine();
  51. if (int.TryParse(screen, out menupick))
  52. {
  53. switch (menupick)
  54. {
  55. case 0:
  56. Console.WriteLine("Thank you for choosing the Bank. Goodbye!");
  57. break;
  58. case 1:
  59. ShowStatus(myAccount);
  60. break;
  61. case 2:
  62. MakeDeposit(myAccount);
  63. break;
  64. case 3:
  65. MakeWithdrawal(myAccount);
  66. break;
  67. //case 4:
  68. // try
  69. // {
  70. // Console.WriteLine(myVehicle.Stop());
  71. // }
  72. // catch (PolicyException e)
  73. // {
  74. // Console.WriteLine("That's a problem...");
  75. // Console.WriteLine(e.Message);
  76. // }
  77. // break;
  78. //case 5:
  79. // try
  80. // {
  81. // Console.WriteLine(myVehicle.ExitVehicle());
  82. // }
  83. // catch (PolicyException e)
  84. // {
  85. // Console.WriteLine("I'm sorry...");
  86. // Console.WriteLine(e.Message);
  87. // }
  88. // break;
  89. default:
  90. Console.WriteLine("Invalid Command!");
  91. menupick = -1;
  92. break;
  93. }
  94. }
  95. else
  96. {
  97. Console.WriteLine("Invalid Command!");
  98. menupick = -1;
  99. }
  100. }
  101.  
  102. Pause();
  103. }
  104.  
  105. static void ShowStatus(Account account)
  106. {
  107. Console.WriteLine("------- Account Status -------");
  108. Console.WriteLine(" Account Number: {0}", account.acctNo);
  109. Console.WriteLine(" Total Balance: {0}", account.balance);
  110. Console.WriteLine(" Checking: {0}", account.checking);
  111. Console.WriteLine(" Savings: {0}", account.savings);
  112. Console.WriteLine("--------------------------------");
  113. }
  114.  
  115. static void MakeDeposit(Account account)
  116. {
  117. string screen;
  118. int value;
  119.  
  120. Console.Write("Which account would you like to deposit money into?");
  121.  
  122. int submenupick = -1;
  123. Account myAccount = null;
  124.  
  125. while (myAccount == null)
  126. {
  127.  
  128. Console.WriteLine("1. Checking");
  129. Console.WriteLine("2. Savings");
  130. screen = Console.ReadLine();
  131. if(int.TryParse(screen, out menupick))
  132. {
  133. if (submenupick == 1)
  134. myAccount = new Deposit();
  135. else if (submenupick == 2)
  136. myAccount = new Withdrawal();
  137. else
  138. Console.WriteLine("Error: Invalid Operation");
  139.  
  140. }
  141. else
  142. {
  143. Console.WriteLine("You must select an operation to proceed.");
  144. }
  145. }
  146.  
  147. Console.Write("Enter the amount you would like to deposit:");
  148. screen = Console.ReadLine();
  149. if (int.TryParse(screen, out value))
  150. {
  151. account.Deposit = value;
  152. }
  153. else
  154. {
  155. Console.WriteLine("Invalid number. Deposit not made.");
  156. }
  157. }
  158.  
  159. private static void MakeWithdrawal(Account account)
  160. {
  161. string screen;
  162. int value;
  163.  
  164. Console.Write("Which account would you like to withdraw money from?");
  165.  
  166. int submenupick = -1;
  167. Account myAccount = null;
  168.  
  169. while (myAccount == null)
  170. {
  171.  
  172. Console.WriteLine("1. Checking");
  173. Console.WriteLine("2. Savings");
  174. screen = Console.ReadLine();
  175. if(int.TryParse(screen, out menupick))
  176. {
  177. if (submenupick == 1)
  178. myAccount = new Deposit();
  179. else if (submenupick == 2)
  180. myAccount = new Withdrawal();
  181. else
  182. Console.WriteLine("Error: Invalid Operation");
  183.  
  184. }
  185. else
  186. {
  187. Console.WriteLine("You must select an operation to proceed.");
  188. }
  189. }
  190.  
  191. Console.Write("Enter the amount you would like to withdraw:");
  192. screen = Console.ReadLine();
  193. if (int.TryParse(screen, out value))
  194. {
  195. account.Deposit = value;
  196. }
  197. else
  198. {
  199. Console.WriteLine("Invalid number. Deposit not made.");
  200. }
  201. }
  202.  
  203. // Console.Write("Enter Direction to Turn (N, S, E, W):");
  204.  
  205. // screen = Console.ReadLine().ToUpper();
  206. // if (screen == "N")
  207. // {
  208. // Console.WriteLine(myVehicle.Turn("North"));
  209. // }
  210. // else if (screen == "S")
  211. // {
  212. // Console.WriteLine(myVehicle.Turn("South"));
  213. // }
  214. // else if (screen == "E")
  215. // {
  216. // Console.WriteLine(myVehicle.Turn("East"));
  217. // }
  218. // else if (screen == "W")
  219. // {
  220. // Console.WriteLine(myVehicle.Turn("West"));
  221. // }
  222. // else
  223. // {
  224. // Console.WriteLine("Invalid Direction. No Change Made.");
  225. // }
  226. //}
  227.  
  228. static void Pause()
  229. {
  230. Console.WriteLine();
  231. Console.Write("Press any key to continue... ");
  232. Console.ReadKey();
  233. Console.WriteLine("\r \r");
  234. }
  235. }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement