Bank Assignment

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2006
Posts: 32
Reputation: schmidty169 is an unknown quantity at this point 
Solved Threads: 0
schmidty169's Avatar
schmidty169 schmidty169 is offline Offline
Light Poster

Bank Assignment

 
0
  #1
Nov 11th, 2008
Here are my parameters to follow: Every Account at the bank keeps track of a balance. In addition, each Account allows users to deposit and withdraw money. Accounts are subdivided into:

SavingsAccount. This type of account has an interest rate associated with it. This rate is used at the end of each month to calculate the amount of interest earned on the account.

CheckingAccount. This type of account does not earn any interest and therefore does not have an interest rate associated with it. Additionally, when account holders perform any type of transaction, there is a fee involved.

Be sure to set up your classes as follows:

Class Account should contain one private data member to store the account balance. It should also have two constructors – one that takes a value representing the starting balance, a second that accepts no values and sets the balance to zero. This class should also provide methods to allow the user to add money to the account (Credit) and take money out of the account (Debit). Be sure that you have validation in place so that the balance is never less than zero. Finally, be sure to provide an accessor method for the balance variable to return the account balance.

Class SavingsAccount should inherit from Account, but also needs to keep track of the interest rate in a private variable. Be sure to provide 2 constructors for this account as well: one that accepts a balance and an interest rate and one that accepts only an interest rate (the balance should then be set to zero). Finally, add a method in this class that will return the amount of interest gained (CalculateInterest). This method will not require any parameters and will simply return the interest based on the current balance multiplied by the interest rate.

Class CheckingAccount should also inherit from Account. However, this class needs to keep track of a transaction fee. This class should have two constructors – one that takes the balance and the transaction fee and another that takes the transaction fee only (and sets the balance to zero). This class will need to redefine Debit and Credit so that the transaction fee is deducted from the balance each time. Be sure that you are calling on the Credit and Debit methods in the Account class appropriately. Also note that if there are not enough funds to debit the money and the transaction fee, then no transaction should take place.

Once you have all three classes working, write a GUI application that allows the user to create one checking and one savings account. Your program should allow the user to work with the accounts and attempt any transactions they wish. Note that for this exercise, you can assume an intelligent user. That is, if the user is expected to enter a number, you can assume that a number will be entered and not a word.

I'm getting use of unassigned variable. I can get around it by dropping AccountChecking checkingAccount = new AccountChecking or Savings in various parts of the code. But I know I should not have to call the same checkingAccount or Savings that often. I included the whole project in a zip also.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace _0804A_IT466_DavidSchmidtII_Unit4_Bank_Account
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18.  
  19. public int caseNumber = 0;
  20. public double chckFee = .50;
  21. public double interestRate = .03;
  22. public double interestBalance;
  23. public double retrieveBalance;
  24.  
  25. private void openSavBtn_Click(object sender, EventArgs e)
  26. {
  27. depositLbl.Visible = true;
  28. withdrawlLbl.Visible = false;
  29. amountTxtBx.Visible = true;
  30. doneBtn.Visible = true;
  31. cancelBtn.Visible = false;
  32. closeSavBtn.Visible = true;
  33. openSavBtn.Visible = false;
  34. chckDepositBtn.Visible = false;
  35. savDepositBtn.Visible = false;
  36. chckWithdrawlBtn.Visible = false;
  37. savWithdrawlBtn.Visible = false;
  38. chckBalanceBtn.Visible = false;
  39. savBalanceBtn.Visible = false;
  40. savInterestBtn.Visible = false;
  41. caseNumber = 1;
  42. }
  43.  
  44. private void closeSavBtn_Click(object sender, EventArgs e)
  45. {
  46. depositLbl.Visible = false;
  47. withdrawlLbl.Visible = false;
  48. amountTxtBx.Visible = false;
  49. doneBtn.Visible = false;
  50. cancelBtn.Visible = false;
  51. closeSavBtn.Visible = false;
  52. openSavBtn.Visible = true;
  53. savDepositBtn.Visible = false;
  54. savWithdrawlBtn.Visible = false;
  55. savBalanceBtn.Visible = false;
  56. savInterestBtn.Visible = false;
  57. caseNumber = 0;
  58. }
  59.  
  60. private void openChckBtn_Click(object sender, EventArgs e)
  61. {
  62. depositLbl.Visible = true;
  63. withdrawlLbl.Visible = false;
  64. amountTxtBx.Visible = true;
  65. doneBtn.Visible = true;
  66. cancelBtn.Visible = false;
  67. closeChckBtn.Visible = true;
  68. openChckBtn.Visible = false;
  69. chckDepositBtn.Visible = false;
  70. savDepositBtn.Visible = false;
  71. chckWithdrawlBtn.Visible = false;
  72. savWithdrawlBtn.Visible = false;
  73. chckBalanceBtn.Visible = false;
  74. savBalanceBtn.Visible = false;
  75. savInterestBtn.Visible = false;
  76. caseNumber = 2;
  77. AccountChecking checkingAccount = new AccountChecking(0, chckFee);
  78. }
  79.  
  80. private void closeChckBtn_Click(object sender, EventArgs e)
  81. {
  82. depositLbl.Visible = false;
  83. withdrawlLbl.Visible = false;
  84. amountTxtBx.Visible = false;
  85. doneBtn.Visible = false;
  86. cancelBtn.Visible = false;
  87. closeChckBtn.Visible = false;
  88. openChckBtn.Visible = true;
  89. chckDepositBtn.Visible = false;
  90. chckWithdrawlBtn.Visible = false;
  91. chckBalanceBtn.Visible = false;
  92. caseNumber = 0;
  93. AccountChecking checkingAccount = new AccountChecking(0);
  94. }
  95.  
  96. private void chckDepositBtn_Click(object sender, EventArgs e)
  97. {
  98. depositLbl.Visible = true;
  99. withdrawlLbl.Visible = false;
  100. amountTxtBx.Visible = true;
  101. doneBtn.Visible = true;
  102. cancelBtn.Visible = true;
  103. chckDepositBtn.Visible = false;
  104. savDepositBtn.Visible = false;
  105. chckWithdrawlBtn.Visible = false;
  106. savWithdrawlBtn.Visible = false;
  107. chckBalanceBtn.Visible = false;
  108. savBalanceBtn.Visible = false;
  109. savInterestBtn.Visible = false;
  110. caseNumber = 3;
  111. }
  112.  
  113. private void chckWithdrawlBtn_Click(object sender, EventArgs e)
  114. {
  115. depositLbl.Visible = false;
  116. withdrawlLbl.Visible = true;
  117. amountTxtBx.Visible = true;
  118. doneBtn.Visible = true;
  119. cancelBtn.Visible = true;
  120. chckDepositBtn.Visible = false;
  121. savDepositBtn.Visible = false;
  122. chckWithdrawlBtn.Visible = false;
  123. savWithdrawlBtn.Visible = false;
  124. chckBalanceBtn.Visible = false;
  125. savBalanceBtn.Visible = false;
  126. savInterestBtn.Visible = false;
  127. caseNumber = 5;
  128. }
  129.  
  130. private void savDepositBtn_Click(object sender, EventArgs e)
  131. {
  132. depositLbl.Visible = true;
  133. withdrawlLbl.Visible = false;
  134. amountTxtBx.Visible = true;
  135. doneBtn.Visible = true;
  136. cancelBtn.Visible = true;
  137. chckDepositBtn.Visible = false;
  138. savDepositBtn.Visible = false;
  139. chckWithdrawlBtn.Visible = false;
  140. savWithdrawlBtn.Visible = false;
  141. chckBalanceBtn.Visible = false;
  142. savBalanceBtn.Visible = false;
  143. savInterestBtn.Visible = false;
  144. caseNumber = 4;
  145. }
  146.  
  147. private void savWithdrawlBtn_Click(object sender, EventArgs e)
  148. {
  149. depositLbl.Visible = false;
  150. withdrawlLbl.Visible = true;
  151. amountTxtBx.Visible = true;
  152. doneBtn.Visible = true;
  153. cancelBtn.Visible = true;
  154. chckDepositBtn.Visible = false;
  155. savDepositBtn.Visible = false;
  156. chckWithdrawlBtn.Visible = false;
  157. savWithdrawlBtn.Visible = false;
  158. chckBalanceBtn.Visible = false;
  159. savBalanceBtn.Visible = false;
  160. savInterestBtn.Visible = false;
  161. caseNumber = 6;
  162. }
  163.  
  164. private void doneBtn_Click(object sender, EventArgs e)
  165. {
  166. depositLbl.Visible = false;
  167. withdrawlLbl.Visible = false;
  168. amountTxtBx.Visible = false;
  169. doneBtn.Visible = false;
  170. cancelBtn.Visible = false;
  171.  
  172. if (openChckBtn.Visible == false)
  173. {
  174. chckDepositBtn.Visible = true;
  175. chckWithdrawlBtn.Visible = true;
  176. chckBalanceBtn.Visible = true;
  177. }
  178.  
  179. if (openSavBtn.Visible == false)
  180. {
  181. savBalanceBtn.Visible = true;
  182. savWithdrawlBtn.Visible = true;
  183. savDepositBtn.Visible = true;
  184. savInterestBtn.Visible = true;
  185. }
  186.  
  187. switch (caseNumber)
  188. {
  189. case 1:
  190. AccountSavings savingsAccount = new AccountSavings(Convert.ToDouble(amountTxtBx.Text), interestRate);
  191. amountTxtBx.Text = "";
  192. break;
  193. case 2:
  194. AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
  195. amountTxtBx.Text = "";
  196. break;
  197. case 3:
  198. checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  199. amountTxtBx.Text = "";
  200. break;
  201. case 4:
  202. savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  203. amountTxtBx.Text = "";
  204. break;
  205. case 5:
  206. checkingAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  207. amountTxtBx.Text = "";
  208. break;
  209. case 6:
  210. savingsAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  211. amountTxtBx.Text = "";
  212. break;
  213. default:
  214. amountTxtBx.Text = "";
  215. break;
  216. }
  217. }
  218.  
  219. private void cancelBtn_Click(object sender, EventArgs e)
  220. {
  221. depositLbl.Visible = false;
  222. withdrawlLbl.Visible = false;
  223. amountTxtBx.Visible = false;
  224. doneBtn.Visible = false;
  225. cancelBtn.Visible = false;
  226.  
  227. if (openChckBtn.Visible == false)
  228. {
  229. chckDepositBtn.Visible = true;
  230. chckWithdrawlBtn.Visible = true;
  231. chckBalanceBtn.Visible = true;
  232. }
  233.  
  234. if (openSavBtn.Visible == false)
  235. {
  236. savBalanceBtn.Visible = true;
  237. savWithdrawlBtn.Visible = true;
  238. savDepositBtn.Visible = true;
  239. savInterestBtn.Visible = true;
  240. }
  241.  
  242. amountTxtBx.Text = " ";
  243. }
  244.  
  245. private void chckBalanceBtn_Click(object sender, EventArgs e)
  246. {
  247. amountTxtBx.Visible = true;
  248. doneBtn.Visible = true;
  249. chckDepositBtn.Visible = false;
  250. savDepositBtn.Visible = false;
  251. chckWithdrawlBtn.Visible = false;
  252. savWithdrawlBtn.Visible = false;
  253. chckBalanceBtn.Visible = false;
  254. savBalanceBtn.Visible = false;
  255. savInterestBtn.Visible = false;
  256. caseNumber = 0;
  257. retrieveBalance = checkingAccount.balanceInquery;
  258. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  259. }
  260.  
  261. private void savBalanceBtn_Click(object sender, EventArgs e)
  262. {
  263. amountTxtBx.Visible = true;
  264. doneBtn.Visible = true;
  265. chckDepositBtn.Visible = false;
  266. savDepositBtn.Visible = false;
  267. chckWithdrawlBtn.Visible = false;
  268. savWithdrawlBtn.Visible = false;
  269. chckBalanceBtn.Visible = false;
  270. savBalanceBtn.Visible = false;
  271. savInterestBtn.Visible = false;
  272. caseNumber = 0;
  273. retrieveBalance = savingsAccount.balanceInquery;
  274. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  275. }
  276.  
  277. private void savInterestBtn_Click(object sender, EventArgs e)
  278. {
  279. amountTxtBx.Visible = true;
  280. doneBtn.Visible = true;
  281. interestBalance = savingsAccount.calcInterest();
  282. amountTxtBx.Text = Convert.ToString(interestBalance);
  283. }
  284.  
  285. private void chckDoneBtn_Click(object sender, EventArgs e)
  286. {
  287. AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
  288. }
  289.  
  290. private void savDoneBtn_Click(object sender, EventArgs e)
  291. {
  292. AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
  293. }
  294. }
  295. }
Attached Files
File Type: zip 0804A_IT466_DavidSchmidtII_Unit4_Bank_Account.zip (60.7 KB, 14 views)
Life should NOT be a journey to the grave with the intention of arriving safely in an attractive and well preserved body, but rather to skid in sideways - Chardonnay in one hand - chocolate in the other - body thoroughly used up, totally worn out and screaming "WOO HOO, What a Ride"
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Bank Assignment

 
0
  #2
Nov 11th, 2008
Your classes arent public - so you cant see them
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: schmidty169 is an unknown quantity at this point 
Solved Threads: 0
schmidty169's Avatar
schmidty169 schmidty169 is offline Offline
Light Poster

Re: Bank Assignment

 
0
  #3
Nov 12th, 2008
I figured it out. I took some liberties in interpreting the assignment. It says to make two constructors, but doesn't explicitly state I had to implement them both in making only one savings and one checking account. As a class is flexible enough to be used with different applications with out being rewritten I decided to just implement one constructor.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace _0804A_IT466_DavidSchmidtII_Unit4_Bank_Account
  11. {
  12. public partial class Form1 : Form
  13. {
  14. AccountSavings savingsAccount = new AccountSavings(.03);
  15. AccountChecking checkingAccount = new AccountChecking(.50);
  16.  
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. public int caseNumber = 0;
  23. public double chckFee = .50;
  24. public double interestRate = .03;
  25. public double interestBalance;
  26. public double retrieveBalance;
  27.  
  28. public void openSavBtn_Click(object sender, EventArgs e)
  29. {
  30. depositLbl.Visible = true;
  31. withdrawlLbl.Visible = false;
  32. amountTxtBx.Visible = true;
  33. doneBtn.Visible = true;
  34. cancelBtn.Visible = false;
  35. closeSavBtn.Visible = true;
  36. openSavBtn.Visible = false;
  37. chckDepositBtn.Visible = false;
  38. savDepositBtn.Visible = false;
  39. chckWithdrawlBtn.Visible = false;
  40. savWithdrawlBtn.Visible = false;
  41. chckBalanceBtn.Visible = false;
  42. savBalanceBtn.Visible = false;
  43. savInterestBtn.Visible = false;
  44. caseNumber = 1;
  45. amountTxtBx.Focus();
  46. }
  47.  
  48. public void closeSavBtn_Click(object sender, EventArgs e)
  49. {
  50. depositLbl.Visible = false;
  51. withdrawlLbl.Visible = false;
  52. amountTxtBx.Visible = false;
  53. doneBtn.Visible = false;
  54. cancelBtn.Visible = false;
  55. closeSavBtn.Visible = false;
  56. openSavBtn.Visible = true;
  57. savDepositBtn.Visible = false;
  58. savWithdrawlBtn.Visible = false;
  59. savBalanceBtn.Visible = false;
  60. savInterestBtn.Visible = false;
  61. caseNumber = 0;
  62. savingsAccount.credit(0);
  63. }
  64.  
  65. public void openChckBtn_Click(object sender, EventArgs e)
  66. {
  67. depositLbl.Visible = true;
  68. withdrawlLbl.Visible = false;
  69. amountTxtBx.Visible = true;
  70. doneBtn.Visible = true;
  71. cancelBtn.Visible = false;
  72. closeChckBtn.Visible = true;
  73. openChckBtn.Visible = false;
  74. chckDepositBtn.Visible = false;
  75. savDepositBtn.Visible = false;
  76. chckWithdrawlBtn.Visible = false;
  77. savWithdrawlBtn.Visible = false;
  78. chckBalanceBtn.Visible = false;
  79. savBalanceBtn.Visible = false;
  80. savInterestBtn.Visible = false;
  81. caseNumber = 2;
  82. amountTxtBx.Focus();
  83. }
  84.  
  85. public void closeChckBtn_Click(object sender, EventArgs e)
  86. {
  87. depositLbl.Visible = false;
  88. withdrawlLbl.Visible = false;
  89. amountTxtBx.Visible = false;
  90. doneBtn.Visible = false;
  91. cancelBtn.Visible = false;
  92. closeChckBtn.Visible = false;
  93. openChckBtn.Visible = true;
  94. chckDepositBtn.Visible = false;
  95. chckWithdrawlBtn.Visible = false;
  96. chckBalanceBtn.Visible = false;
  97. caseNumber = 0;
  98. checkingAccount.credit(0 + chckFee);
  99. }
  100.  
  101. public void chckDepositBtn_Click(object sender, EventArgs e)
  102. {
  103. depositLbl.Visible = true;
  104. withdrawlLbl.Visible = false;
  105. amountTxtBx.Visible = true;
  106. doneBtn.Visible = true;
  107. cancelBtn.Visible = true;
  108. chckDepositBtn.Visible = false;
  109. savDepositBtn.Visible = false;
  110. chckWithdrawlBtn.Visible = false;
  111. savWithdrawlBtn.Visible = false;
  112. chckBalanceBtn.Visible = false;
  113. savBalanceBtn.Visible = false;
  114. savInterestBtn.Visible = false;
  115. caseNumber = 3;
  116. amountTxtBx.Focus();
  117. }
  118.  
  119. public void chckWithdrawlBtn_Click(object sender, EventArgs e)
  120. {
  121. depositLbl.Visible = false;
  122. withdrawlLbl.Visible = true;
  123. amountTxtBx.Visible = true;
  124. doneBtn.Visible = true;
  125. cancelBtn.Visible = true;
  126. chckDepositBtn.Visible = false;
  127. savDepositBtn.Visible = false;
  128. chckWithdrawlBtn.Visible = false;
  129. savWithdrawlBtn.Visible = false;
  130. chckBalanceBtn.Visible = false;
  131. savBalanceBtn.Visible = false;
  132. savInterestBtn.Visible = false;
  133. caseNumber = 5;
  134. amountTxtBx.Focus();
  135. }
  136.  
  137. public void savDepositBtn_Click(object sender, EventArgs e)
  138. {
  139. depositLbl.Visible = true;
  140. withdrawlLbl.Visible = false;
  141. amountTxtBx.Visible = true;
  142. doneBtn.Visible = true;
  143. cancelBtn.Visible = true;
  144. chckDepositBtn.Visible = false;
  145. savDepositBtn.Visible = false;
  146. chckWithdrawlBtn.Visible = false;
  147. savWithdrawlBtn.Visible = false;
  148. chckBalanceBtn.Visible = false;
  149. savBalanceBtn.Visible = false;
  150. savInterestBtn.Visible = false;
  151. caseNumber = 4;
  152. amountTxtBx.Focus();
  153. }
  154.  
  155. public void savWithdrawlBtn_Click(object sender, EventArgs e)
  156. {
  157. depositLbl.Visible = false;
  158. withdrawlLbl.Visible = true;
  159. amountTxtBx.Visible = true;
  160. doneBtn.Visible = true;
  161. cancelBtn.Visible = true;
  162. chckDepositBtn.Visible = false;
  163. savDepositBtn.Visible = false;
  164. chckWithdrawlBtn.Visible = false;
  165. savWithdrawlBtn.Visible = false;
  166. chckBalanceBtn.Visible = false;
  167. savBalanceBtn.Visible = false;
  168. savInterestBtn.Visible = false;
  169. caseNumber = 6;
  170. amountTxtBx.Focus();
  171. }
  172.  
  173. public void doneBtn_Click(object sender, EventArgs e)
  174. {
  175. depositLbl.Visible = false;
  176. withdrawlLbl.Visible = false;
  177. amountTxtBx.Visible = false;
  178. doneBtn.Visible = false;
  179. cancelBtn.Visible = false;
  180.  
  181. if (openChckBtn.Visible == false)
  182. {
  183. chckDepositBtn.Visible = true;
  184. chckWithdrawlBtn.Visible = true;
  185. chckBalanceBtn.Visible = true;
  186. }
  187.  
  188. if (openSavBtn.Visible == false)
  189. {
  190. savBalanceBtn.Visible = true;
  191. savWithdrawlBtn.Visible = true;
  192. savDepositBtn.Visible = true;
  193. savInterestBtn.Visible = true;
  194. }
  195.  
  196. switch (caseNumber)
  197. {
  198. case 1:
  199. savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  200. amountTxtBx.Text = "";
  201. break;
  202. case 2:
  203. checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text) + chckFee);
  204. amountTxtBx.Text = "";
  205. break;
  206. case 3:
  207. checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  208. amountTxtBx.Text = "";
  209. break;
  210. case 4:
  211. savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  212. amountTxtBx.Text = "";
  213. break;
  214. case 5:
  215. checkingAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  216. amountTxtBx.Text = "";
  217. break;
  218. case 6:
  219. savingsAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  220. amountTxtBx.Text = "";
  221. break;
  222. default:
  223. amountTxtBx.Text = "";
  224. break;
  225. }
  226. }
  227.  
  228. public void cancelBtn_Click(object sender, EventArgs e)
  229. {
  230. depositLbl.Visible = false;
  231. withdrawlLbl.Visible = false;
  232. amountTxtBx.Visible = false;
  233. doneBtn.Visible = false;
  234. cancelBtn.Visible = false;
  235.  
  236. if (openChckBtn.Visible == false)
  237. {
  238. chckDepositBtn.Visible = true;
  239. chckWithdrawlBtn.Visible = true;
  240. chckBalanceBtn.Visible = true;
  241. }
  242.  
  243. if (openSavBtn.Visible == false)
  244. {
  245. savBalanceBtn.Visible = true;
  246. savWithdrawlBtn.Visible = true;
  247. savDepositBtn.Visible = true;
  248. savInterestBtn.Visible = true;
  249. }
  250.  
  251. amountTxtBx.Text = " ";
  252. }
  253.  
  254. public void chckBalanceBtn_Click(object sender, EventArgs e)
  255. {
  256. amountTxtBx.Visible = true;
  257. doneBtn.Visible = true;
  258. chckDepositBtn.Visible = false;
  259. savDepositBtn.Visible = false;
  260. chckWithdrawlBtn.Visible = false;
  261. savWithdrawlBtn.Visible = false;
  262. chckBalanceBtn.Visible = false;
  263. savBalanceBtn.Visible = false;
  264. savInterestBtn.Visible = false;
  265. caseNumber = 0;
  266. retrieveBalance = checkingAccount.balanceInquery;
  267. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  268. }
  269.  
  270. public void savBalanceBtn_Click(object sender, EventArgs e)
  271. {
  272. amountTxtBx.Visible = true;
  273. doneBtn.Visible = true;
  274. chckDepositBtn.Visible = false;
  275. savDepositBtn.Visible = false;
  276. chckWithdrawlBtn.Visible = false;
  277. savWithdrawlBtn.Visible = false;
  278. chckBalanceBtn.Visible = false;
  279. savBalanceBtn.Visible = false;
  280. savInterestBtn.Visible = false;
  281. caseNumber = 0;
  282. retrieveBalance = savingsAccount.balanceInquery;
  283. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  284. }
  285.  
  286. public void savInterestBtn_Click(object sender, EventArgs e)
  287. {
  288. amountTxtBx.Visible = true;
  289. doneBtn.Visible = true;
  290. interestBalance = savingsAccount.calcInterest();
  291. amountTxtBx.Text = Convert.ToString(interestBalance);
  292. }
  293. }
  294. }
Life should NOT be a journey to the grave with the intention of arriving safely in an attractive and well preserved body, but rather to skid in sideways - Chardonnay in one hand - chocolate in the other - body thoroughly used up, totally worn out and screaming "WOO HOO, What a Ride"
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: Bank Assignment

 
1
  #4
Nov 12th, 2008
beforehand, sorry for my english...
I have some advices for you:
1. You have a lot of repeating code in your program. You should take out it to a method(s) and then call it...
(also in doneBtn_Click method you have switch operator, that no matter what do this: amountTxtBx.Text = ""; you could place this before of after switch)
2. And you can make you switch operator shorter (it has equals cases)
3. Instead of creating variables chckFee, interestRate I would create an accessors in classes to get them.
I think, that's all for a first sight.
4. Instead caseNumber you could use an enum, with work, you want to lock in. I think it would be more understandable.
Last edited by Antenka; Nov 12th, 2008 at 1:59 pm.
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: Bank Assignment

 
0
  #5
Nov 12th, 2008
I'm totally agree with the charmant Antenka
Last edited by Jugortha; Nov 12th, 2008 at 6:57 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: schmidty169 is an unknown quantity at this point 
Solved Threads: 0
schmidty169's Avatar
schmidty169 schmidty169 is offline Offline
Light Poster

Re: Bank Assignment

 
1
  #6
Nov 26th, 2008
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace _0804A_IT466_DavidSchmidtII_Unit5_Bank_Account
  11. {
  12.  
  13. public partial class Form1 : Form
  14. {
  15. AccountSavings savingsAccount = new AccountSavings(interestRate); // create a savings account
  16. AccountChecking checkingAccount = new AccountChecking(chckFee); // create a checking account
  17.  
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. public int caseNumber = 0; // used to determin which method is envoking the done button
  24. static double chckFee = .50; // variable to store checking fee
  25. static double interestRate = .03; // variable to store interest rate
  26. public double interestBalance; // variable used to store retrieval of interest earned
  27. public double retrieveBalance; // variable used to store retrieval of account balance
  28.  
  29. // retrieve initial deposit and enable savings account buttons
  30. public void openSavBtn_Click(object sender, EventArgs e)
  31. {
  32. openAccountBtns();
  33. enableAmountDisplay();
  34. hideChckBtns();
  35. hideSavBtns();
  36. caseNumber = 1;
  37. amountTxtBx.Focus();
  38. } // end openSavBtn method
  39.  
  40. // add additional deposit to savings account
  41. public void savDepositBtn_Click(object sender, EventArgs e)
  42. {
  43. enabledepositBtns();
  44. enableAmountDisplay();
  45. hideChckBtns();
  46. hideSavBtns();
  47. caseNumber = 3;
  48. amountTxtBx.Focus();
  49. } // end savDepositBtn method
  50.  
  51. // withdrawl money from savings account
  52. public void savWithdrawlBtn_Click(object sender, EventArgs e)
  53. {
  54. enableWithdrawlBtns();
  55. enableAmountDisplay();
  56. hideChckBtns();
  57. hideSavBtns();
  58. caseNumber = 5;
  59. amountTxtBx.Focus();
  60. } // end savWithdrawlBtn method
  61.  
  62. // zero out savings account and disable account buttons
  63. public void closeSavBtn_Click(object sender, EventArgs e)
  64. {
  65. hideModifyAccountBtns();
  66. hideSavBtns();
  67. closeSavBtn.Visible = false;
  68. openSavBtn.Visible = true;
  69. caseNumber = 0;
  70. savingsAccount.debit(savingsAccount.balanceInquery);
  71. } // end closeSavBtn method
  72.  
  73. // retrieve initial deposit and enable checking account buttons
  74. public void openChckBtn_Click(object sender, EventArgs e)
  75. {
  76. openAccountBtns();
  77. enableAmountDisplay();
  78. hideChckBtns();
  79. hideSavBtns();
  80. caseNumber = 2;
  81. amountTxtBx.Focus();
  82. } // end openChckBtn method
  83.  
  84. // add additional deposit to checking account
  85. public void chckDepositBtn_Click(object sender, EventArgs e)
  86. {
  87. enabledepositBtns();
  88. enableAmountDisplay();
  89. hideChckBtns();
  90. hideSavBtns();
  91. caseNumber = 4;
  92. amountTxtBx.Focus();
  93. } // end chckDepositBtn method
  94.  
  95. // withdrawl money from chekcing account
  96. public void chckWithdrawlBtn_Click(object sender, EventArgs e)
  97. {
  98. enableWithdrawlBtns();
  99. enableAmountDisplay();
  100. hideChckBtns();
  101. hideSavBtns();
  102. caseNumber = 6;
  103. amountTxtBx.Focus();
  104. } // end chkWithdrawlBtn method
  105.  
  106. // zero out checking account and disable account buttons
  107. public void closeChckBtn_Click(object sender, EventArgs e)
  108. {
  109. hideModifyAccountBtns();
  110. hideChckBtns();
  111. closeChckBtn.Visible = false;
  112. openChckBtn.Visible = true;
  113. caseNumber = 0;
  114. checkingAccount.debit(checkingAccount.balanceInquery + chckFee);
  115. } // end closeChckBtn method
  116.  
  117. // use switch/case to determin action to be performed when pressed
  118. public void doneBtn_Click(object sender, EventArgs e)
  119. {
  120. hideModifyAccountBtns();
  121.  
  122. try
  123. {
  124. switch (caseNumber)
  125. {
  126. case 1:
  127. savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  128. if (savingsAccount.negativeNumber == false)
  129. {
  130. closeSavBtn.Visible = true;
  131. openSavBtn.Visible = false;
  132. }
  133. break;
  134. case 2:
  135. checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text) + chckFee);
  136. if (checkingAccount.negativeNumber == false)
  137. {
  138. closeChckBtn.Visible = true;
  139. openChckBtn.Visible = false;
  140. }
  141. break;
  142. case 3:
  143. savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  144. break;
  145. case 4:
  146. checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text));
  147. break;
  148. case 5:
  149. savingsAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  150. break;
  151. case 6:
  152. checkingAccount.debit(Convert.ToDouble(amountTxtBx.Text));
  153. break;
  154. default:
  155. clearAmountTxtBx();
  156. break;
  157. }
  158. } // end try
  159. catch (FormatException)
  160. {
  161. MessageBox.Show("You must enter an integer.", "Invalid Number Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
  162. } // end catch
  163. finally
  164. {
  165. clearAmountTxtBx();
  166. // check which accounts are opened and enable transactional buttons
  167. if (openChckBtn.Visible == false)
  168. {
  169. enableChckBtns();
  170. }
  171.  
  172. if (openSavBtn.Visible == false)
  173. {
  174. enableSavBtns();
  175. }
  176. }
  177. } // end doneBtn method
  178.  
  179. // cancel transaction
  180. public void cancelBtn_Click(object sender, EventArgs e)
  181. {
  182. hideModifyAccountBtns();
  183.  
  184. if (openChckBtn.Visible == false)
  185. {
  186. enableChckBtns();
  187. }
  188.  
  189. if (openSavBtn.Visible == false)
  190. {
  191. enableSavBtns();
  192. }
  193.  
  194. amountTxtBx.Text = " ";
  195. } // end cancelBtn method
  196.  
  197. // retrieve checking account balance
  198. public void chckBalanceBtn_Click(object sender, EventArgs e)
  199. {
  200. enableAmountDisplay();
  201. hideChckBtns();
  202. hideSavBtns();
  203. caseNumber = 0;
  204. retrieveBalance = checkingAccount.balanceInquery;
  205. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  206. } // end chckBalanceBtn method
  207.  
  208. // retrieve savings account balance
  209. public void savBalanceBtn_Click(object sender, EventArgs e)
  210. {
  211. enableAmountDisplay();
  212. hideChckBtns();
  213. hideSavBtns();
  214. caseNumber = 0;
  215. retrieveBalance = savingsAccount.balanceInquery;
  216. amountTxtBx.Text = Convert.ToString(retrieveBalance);
  217. } // end savBalanceBtn method
  218.  
  219. // retrieve interest earned
  220. public void savInterestBtn_Click(object sender, EventArgs e)
  221. {
  222. enableAmountDisplay();
  223. interestBalance = savingsAccount.calcInterest();
  224. amountTxtBx.Text = Convert.ToString(interestBalance);
  225. } // end savInterestBtn method
  226.  
  227. // clear amount text box
  228. public void clearAmountTxtBx()
  229. {
  230. amountTxtBx.Text = "";
  231. } // end closeAccountBtns method
  232.  
  233. //--------------------- Visible Buttons Methods ---------------------------
  234.  
  235. // hide savings account transaction buttons
  236. public void hideSavBtns()
  237. {
  238. savDepositBtn.Visible = false;
  239. savWithdrawlBtn.Visible = false;
  240. savBalanceBtn.Visible = false;
  241. savInterestBtn.Visible = false;
  242. } // end hideSavBtns method
  243.  
  244. // enable savings account transaction buttons
  245. public void enableSavBtns()
  246. {
  247. savBalanceBtn.Visible = true;
  248. savWithdrawlBtn.Visible = true;
  249. savDepositBtn.Visible = true;
  250. savInterestBtn.Visible = true;
  251. } // end enableSavBtns method
  252.  
  253. // hide checking account transaction buttons
  254. public void hideChckBtns()
  255. {
  256. chckDepositBtn.Visible = false;
  257. chckWithdrawlBtn.Visible = false;
  258. chckBalanceBtn.Visible = false;
  259. } // end hideChckBtns method
  260.  
  261. // enable checking account transaction buttons
  262. public void enableChckBtns()
  263. {
  264. chckDepositBtn.Visible = true;
  265. chckWithdrawlBtn.Visible = true;
  266. chckBalanceBtn.Visible = true;
  267. } // end enableChckBtns method
  268.  
  269. // hide transaction buttons
  270. public void hideModifyAccountBtns()
  271. {
  272. depositLbl.Visible = false;
  273. withdrawlLbl.Visible = false;
  274. amountTxtBx.Visible = false;
  275. doneBtn.Visible = false;
  276. cancelBtn.Visible = false;
  277. } // end hideTransModifyBtns method
  278.  
  279. // enable done button and amount text box
  280. public void enableAmountDisplay()
  281. {
  282. amountTxtBx.Visible = true;
  283. doneBtn.Visible = true;
  284. } // end enableAmountDisplay method
  285.  
  286. // enable withdrawl buttons
  287. public void enableWithdrawlBtns()
  288. {
  289. depositLbl.Visible = false;
  290. withdrawlLbl.Visible = true;
  291. cancelBtn.Visible = true;
  292. } // end enableWithdrawlBtns method
  293.  
  294. // enable deposit buttons
  295. public void enabledepositBtns()
  296. {
  297. depositLbl.Visible = true;
  298. withdrawlLbl.Visible = false;
  299. cancelBtn.Visible = true;
  300. } // end enabledepositBtns method
  301.  
  302. // open account buttons
  303. public void openAccountBtns()
  304. {
  305. depositLbl.Visible = true;
  306. withdrawlLbl.Visible = false;
  307. cancelBtn.Visible = false;
  308.  
  309. } // end openAccountBtns method
  310.  
  311. } // end Class Form
  312. } // end namespace
Based on Antenka's advice here is clearer code!
Life should NOT be a journey to the grave with the intention of arriving safely in an attractive and well preserved body, but rather to skid in sideways - Chardonnay in one hand - chocolate in the other - body thoroughly used up, totally worn out and screaming "WOO HOO, What a Ride"
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC