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.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _0804A_IT466_DavidSchmidtII_Unit4_Bank_Account
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int caseNumber = 0;
public double chckFee = .50;
public double interestRate = .03;
public double interestBalance;
public double retrieveBalance;
private void openSavBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = true;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = false;
closeSavBtn.Visible = true;
openSavBtn.Visible = false;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 1;
}
private void closeSavBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = false;
doneBtn.Visible = false;
cancelBtn.Visible = false;
closeSavBtn.Visible = false;
openSavBtn.Visible = true;
savDepositBtn.Visible = false;
savWithdrawlBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 0;
}
private void openChckBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = true;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = false;
closeChckBtn.Visible = true;
openChckBtn.Visible = false;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 2;
AccountChecking checkingAccount = new AccountChecking(0, chckFee);
}
private void closeChckBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = false;
doneBtn.Visible = false;
cancelBtn.Visible = false;
closeChckBtn.Visible = false;
openChckBtn.Visible = true;
chckDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
caseNumber = 0;
AccountChecking checkingAccount = new AccountChecking(0);
}
private void chckDepositBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = true;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 3;
}
private void chckWithdrawlBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = true;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 5;
}
private void savDepositBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = true;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 4;
}
private void savWithdrawlBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = true;
amountTxtBx.Visible = true;
doneBtn.Visible = true;
cancelBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 6;
}
private void doneBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = false;
doneBtn.Visible = false;
cancelBtn.Visible = false;
if (openChckBtn.Visible == false)
{
chckDepositBtn.Visible = true;
chckWithdrawlBtn.Visible = true;
chckBalanceBtn.Visible = true;
}
if (openSavBtn.Visible == false)
{
savBalanceBtn.Visible = true;
savWithdrawlBtn.Visible = true;
savDepositBtn.Visible = true;
savInterestBtn.Visible = true;
}
switch (caseNumber)
{
case 1:
AccountSavings savingsAccount = new AccountSavings(Convert.ToDouble(amountTxtBx.Text), interestRate);
amountTxtBx.Text = "";
break;
case 2:
AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
amountTxtBx.Text = "";
break;
case 3:
checkingAccount.credit(Convert.ToDouble(amountTxtBx.Text));
amountTxtBx.Text = "";
break;
case 4:
savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
amountTxtBx.Text = "";
break;
case 5:
checkingAccount.debit(Convert.ToDouble(amountTxtBx.Text));
amountTxtBx.Text = "";
break;
case 6:
savingsAccount.debit(Convert.ToDouble(amountTxtBx.Text));
amountTxtBx.Text = "";
break;
default:
amountTxtBx.Text = "";
break;
}
}
private void cancelBtn_Click(object sender, EventArgs e)
{
depositLbl.Visible = false;
withdrawlLbl.Visible = false;
amountTxtBx.Visible = false;
doneBtn.Visible = false;
cancelBtn.Visible = false;
if (openChckBtn.Visible == false)
{
chckDepositBtn.Visible = true;
chckWithdrawlBtn.Visible = true;
chckBalanceBtn.Visible = true;
}
if (openSavBtn.Visible == false)
{
savBalanceBtn.Visible = true;
savWithdrawlBtn.Visible = true;
savDepositBtn.Visible = true;
savInterestBtn.Visible = true;
}
amountTxtBx.Text = " ";
}
private void chckBalanceBtn_Click(object sender, EventArgs e)
{
amountTxtBx.Visible = true;
doneBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 0;
retrieveBalance = checkingAccount.balanceInquery;
amountTxtBx.Text = Convert.ToString(retrieveBalance);
}
private void savBalanceBtn_Click(object sender, EventArgs e)
{
amountTxtBx.Visible = true;
doneBtn.Visible = true;
chckDepositBtn.Visible = false;
savDepositBtn.Visible = false;
chckWithdrawlBtn.Visible = false;
savWithdrawlBtn.Visible = false;
chckBalanceBtn.Visible = false;
savBalanceBtn.Visible = false;
savInterestBtn.Visible = false;
caseNumber = 0;
retrieveBalance = savingsAccount.balanceInquery;
amountTxtBx.Text = Convert.ToString(retrieveBalance);
}
private void savInterestBtn_Click(object sender, EventArgs e)
{
amountTxtBx.Visible = true;
doneBtn.Visible = true;
interestBalance = savingsAccount.calcInterest();
amountTxtBx.Text = Convert.ToString(interestBalance);
}
private void chckDoneBtn_Click(object sender, EventArgs e)
{
AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
}
private void savDoneBtn_Click(object sender, EventArgs e)
{
AccountChecking checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
}
}
}