• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Bank Assignment

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. http://purplefrogit.com/0804A_IT466_DavidSchmidtII_Unit4_Bank_Account.zip
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);
        }
    }
}

Open in new window

0
schmidty169
Asked:
schmidty169
  • 6
  • 6
2 Solutions
 
anarki_jimbelCommented:
OK, what you need to do - is to declare the account just once. I.e. at the top of your form class. Something like below (see also snippet)

        private AccountSavings savingsAccount;// need to be set berfore using
        private AccountChecking checkingAccount; //need to be set before using

When you create an accout - you set the variable. There is a problem in your code - you have two places to  set the variable: in a common "Done" button and in special buttons for each type of the account. I believe should be the only place.
Also, you may need toiverify in the code that the variable is set. In other words you check the variable if it's not null.

About entering numbers. What happens if sombody enters wrong characterss into textboxes? It's better to use something like Double.TryParse methods. See examples in the internet.

Ask questions.

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
    {
 
        private AccountSavings savingsAccount;// need to be set berfore using
        private AccountChecking checkingAccount; //need to be set before using
 
        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:
                    savingsAccount = new AccountSavings(Convert.ToDouble(amountTxtBx.Text), interestRate);
                    amountTxtBx.Text = "";
                    break;
                case 2:
                    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)
        {
            checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
        }
 
        private void savDoneBtn_Click(object sender, EventArgs e)
        {
            checkingAccount = new AccountChecking(Convert.ToDouble(amountTxtBx.Text), chckFee);
        }
    }
}

Open in new window

0
 
schmidty169Author Commented:
That was one of the various locations I tried it. It will clear up all the unassigned error in the lower methods, but I still get it in the Switch/Case. I had it in the two spots mentioned because I originally had it in just the switch/case and that didn't work, so I created the second done buttons. The obviously didn't work either.
0
 
anarki_jimbelCommented:
OK, the code I put as a snippet is compiling with no error (I only commented line with Im port LINQ).
So if you copy my code yours project should compile too. Try and let me know.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
schmidty169Author Commented:
I figured it out. I agree with your earlier statement about having the AccountSavings savingsAccount and checking created a few times. I was never comfortable with this solution, seemed too spaghetti code to me. I also didn't think it made send in this setting to use both constructors.  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. It is so different to code for a class you feel like your working in a bubble that doesn't correspond to the real world. Just like not having to validate the data as it is just an assignment and we were told we didn't have to. (But then again this weeks assignment is to add validation to the program, lol)
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
    {
        AccountSavings savingsAccount = new AccountSavings(.03);
        AccountChecking checkingAccount = new AccountChecking(.50);
 
        public Form1()
        {
            InitializeComponent();            
        }
 
        public int caseNumber = 0;
        public double chckFee = .50;
        public double interestRate = .03;
        public double interestBalance;
        public double retrieveBalance;
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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;
            savingsAccount.credit(0);
        }
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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;
            checkingAccount.credit(0 + chckFee);
        }
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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;
            amountTxtBx.Focus();
        }
 
        public 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:
                    savingsAccount.credit(Convert.ToDouble(amountTxtBx.Text));
                    amountTxtBx.Text = "";
                    break;
                case 2:
                    checkingAccount.credit(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;
            }
        }
 
        public 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 = " ";
        }
 
        public 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);
        }
 
        public 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);            
        }
 
        public void savInterestBtn_Click(object sender, EventArgs e)
        {
            amountTxtBx.Visible = true;
            doneBtn.Visible = true;
            interestBalance = savingsAccount.calcInterest();
            amountTxtBx.Text = Convert.ToString(interestBalance);
        }
    }
}

Open in new window

0
 
anarki_jimbelCommented:
Hmmm... I'd say that the author's solution closely resembles mines one :)
And it definitely solves the problem stated in the original question.
0
 
schmidty169Author Commented:
The problem being all you suggested was to really add the block to the beginning which I had already tried prior to the post. Even with that there you still get a few unassigned variable errors. Out of the original 8 it only solves 2 of them. In order to get them all you have to use the same statement calling accountSavings and checking if 4 different spots, in essence reinitializing it over and over. This is not acceptable. My rewrite address all the issues and is cleaner code. I have an email sitting in my work sent items dated 10/10/08 4:06 pm with that code included in it. So I had already tried it the day before. Hey you want some points I'll throw you a bone for trying to help, I appreciate it, but my intent was not to bone you, I just figured you did not add anything to my solution that I did not already try myself. I figured out the solution on my own with no outside help by approaching the problem from a different stand point and changing the requirements.
0
 
schmidty169Author Commented:
If I'm understanding this process a moderator will join the discussion, I will accept their ruling and award what ever point if any they deem fair. Like I said I wasn't trying to bone anyone, maybe my interpretation of things was wrong and accept any fair judgment, even let me know what you think it fair anarki_jimbel I'm listening.
0
 
anarki_jimbelCommented:
dear schmidty169

I have downloaded yours solution and fixed all the compile errors. I could run the project, click buttons etc. It means I HAD NO any anassigned variables. I would not be able to run the application.

Another thing, often experts  provide just an idea or point the right way. It's hard to demand more. I spent at least half an hour working with your question and gave the working solution by fixing all compile errors (instead just giving you an advise how to do that). You didn't mention you tried this way and anyway it didn't work for you because you apparently did something wrong. Anyone may check my solution and at least it will compile.
0
 
anarki_jimbelCommented:
My gess is that you copied just a part of my code, not entire class. Tha't why you still had some errors. I make changes in different parts of the class, not only in declarations part at the beginning.
0
 
schmidty169Author Commented:
Originally posted 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. Indicating I do not want to use the code multiple times. Just because your solution works, doesnt make it the best solution. In your solution you call someAccount = new AccountSome 8 times. Obviously this is not in line with my looking for not only a solution to clear the unassigned variable messages, but to more efficiently address my code. Now my initial call AccountSavings savingsAccount = new AccountSavings(.03); and AccountChecking checkingAccount = new AccountChecking(.50); is not entirely the same as your private AccountSavings savingsAccount;// need to be set berfore using and private AccountChecking checkingAccount; //need to be set before using That is as close to your code as I get. I understand you invested time in trying to come up with a solution that I did not use and appreciate that. But I didnt use any of your code. Like I said I have an email I sent from my work email to my personal email with that line already in it. I had been working on this for days and tried several different approaches. I also dont think I have ever seen points awarded to experts on effort, only for accepted solutions. Ive seen points split when different parts from different sources are used in the final outcome. But Ive never seen, well your solution didnt work for me, but Ill give you points for trying.

Your other statement My gess is that you copied just a part of my code, not entire class. Tha't why you still had some errors. I make changes in different parts of the class, not only in declarations part at the beginning. Well that isnt true I didnt copy any of your code so now that isnt why I got those errors I mentioned when I had tried to declare them at the top as in my working code. As I indicated I tried that days before and still received the unassigned variable errors in two spots. I only saw that in your code and did not try it, as I already failed using that approach. If you made other changes that allowed yours to work I did not notice. I only saw the top part of the code, I scrolled through seeing you left the multiple repeat calls and again this is not what I wanted. I then went back to the drawing board and created the working code I posted for the reasons I posted.

Now like I said earlier, I dont feel I used any of your code, but to avoid a pissing contest and to show appreciation for the effort I was willing to award some points to you. In keeping with my original statement of not feeling my multiple Account = new Account (and yours) was in good coding practices and with your statement When you create an accout - you set the variable. There is a problem in your code - you have two places to set the variable: in a common "Done" button and in special buttons for each type of the account. I believe should be the only place. Thus giving me confirmation that my original assessment was true, and thus maybe influencing my decision to rethink the problem. To go back to the source (the assignment) and reevaluate what was being asked of me. That statement alone by you could possiblely have had a far greater impact then your code. So Im willing to acknowledge contribution (often experts  provide just an idea or point the right way. It's hard to demand more.), but not for your code. So Im willing to split the points with you, sound fair?
0
 
anarki_jimbelCommented:
Dear moderator,

The problem was, at least how I understood it, in errors author coud not resolve. His code won't compile. I fixed errors. I don't really think I have to provide solutions for the author. Especially because it's obviously an assignment. And it is definitely cheating from my point of view.

Anyway. Please close the question - I'm not interested in ANY points.

0
 
schmidty169Author Commented:
I never asked you to write my code. I asked "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 (which again leads to the I already had placed the code in the same spot as yours prior to posting). But I know I should not have to call the same checkingAccount or Savings that often." I thought I was clear in so far as my issue. And this is cheating? "Especially because it's obviously an assignment" What was your first clue? I stated this was an assignment in the title, listed what the assignment was. I don't think asking for help when you have created bad code it cheating? If I had direct access to the teacher at that moment I would have went to him. Do you know how many people on the web ask for help with their homework? It is only cheating when you don't do the work and copy from someone else. Asking someone more knowledgeable than you for help is not cheating. Otherwise every kid that uses a calculator, dictionary or library for additional resources is cheating. First of you dispute my closing the question because I did not use your solution and you felt you were entitled to something. Then after pissing in the wind for a while, now you don't want any points? But you did not solve one of my original questions "But I know I should not have to call the same checkingAccount or Savings that often." I wanted some one to point me in the right direction, hell if you sent me to a tutorial that explained or taught me something so I understood why my code was designed so badly as to require this obviously uneccessary repeating calls. I would have been fine with that. "Another thing, often experts  provide just an idea or point the right way. It's hard to demand more." But all you did was slap a band aid on it and say here it doesn't crash. "I spent at least half an hour working with your question and gave the working solution by fixing all compile errors (instead just giving you an advise how to do that)." If I had taken your code with out understanding how or why, that would be cheating. But I figured out the how and why, that is not cheating. Actually if you look at that is it a contradiction of statements: experts  provide just an idea or point the right way vs instead just giving you an advise how to do that. Now a few of your comments got me thinking and researching different tutorials, achieving understanding. I felt bad you spent some time (1/2 hour) on this (but then again how many times do you read threads here were a lot of people spend lots of time and only the person with the best solution gets points, do you whine about those too?) That is why I was gracious enough to give you an assisted solution and want to give you some points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now