Advertisement
wis3_guy

ATM Simulator v1.1

Mar 7th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 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 Regions Bank");
  19. Console.WriteLine("Please Select an Account");
  20. Console.WriteLine("1. Checking");
  21. Console.WriteLine("2. Savings");
  22. screen = Console.ReadLine();
  23. if(int.TryParse(screen, out menupick))
  24. {
  25. if (menupick == 1)
  26. myAccount = new Checking(8527419630);
  27. else if (menupick == 2)
  28. myAccount = new Savings(852741520);
  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("0. Quit");
  46. Console.WriteLine();
  47. Console.Write("Enter Command: ");
  48. screen = Console.ReadLine();
  49. if (int.TryParse(screen, out menupick))
  50. {
  51. switch (menupick)
  52. {
  53. case 0:
  54. Console.WriteLine("Thank you for choosing the Bank. Goodbye!");
  55. break;
  56. case 1:
  57. ShowStatus(myAccount);
  58. break;
  59. case 2:
  60. MakeDeposit(myAccount);
  61. break;
  62. case 3:
  63. MakeWithdrawal(myAccount);
  64. break;
  65.  
  66. default:
  67. Console.WriteLine("Invalid Command!");
  68. menupick = -1;
  69. break;
  70. }
  71. }
  72. else
  73. {
  74. Console.WriteLine("Invalid Command!");
  75. menupick = -1;
  76. }
  77. }
  78.  
  79. Pause();
  80. }
  81.  
  82. static void ShowStatus(Account account)
  83. {
  84. Console.WriteLine("------- Account Status -------");
  85. Console.WriteLine(" Account Number: {0}", account.AcctNo);
  86. Console.WriteLine(" Total Balance: {0}", account.Balance);
  87. Console.WriteLine("--------------------------------");
  88. }
  89.  
  90. static void MakeDeposit(Account account)
  91. {
  92. string screen;
  93. double amount;
  94.  
  95. Console.Write("Enter an amount you would like to deposit (must be a positive number):");
  96. screen = Console.ReadLine();
  97. if (double.TryParse(screen, out amount))
  98. {
  99. Account.Deposit(amount);
  100. Console.WriteLine("New Balance" + Account.Balance);
  101.  
  102. }
  103. else
  104. {
  105. Console.WriteLine("Error: invalid number. Please try again.");
  106. }
  107. }
  108.  
  109. private static void MakeWithdrawal(Account account)
  110. {
  111. string screen;
  112. double amount;
  113. Console.Write("Enter an amount you would like to withdraw");
  114.  
  115. screen = Console.ReadLine();
  116. if (double.TryParse(screen, out amount))
  117. {
  118. Account.Withdrawal(amount);
  119. Console.WriteLine("New Balance" + Account.Balance);
  120. }
  121. else
  122. {
  123. Console.WriteLine("Error: invalid number. Please try again.");
  124. }
  125.  
  126.  
  127. }
  128.  
  129. static void Pause()
  130. {
  131. Console.WriteLine();
  132. Console.Write("Press any key to continue... ");
  133. Console.ReadKey();
  134. Console.WriteLine("\r \r");
  135. }
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement