4 Replies - 594 Views - Last Post: 22 June 2011 - 04:28 PM Rate Topic: -----

#1 feastfulsaint  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 15-July 10

Having an Error and I just can't see why

Posted 21 June 2011 - 05:52 PM

Been at this for over 4 hours and I am completely stumped. I am thinking about scrapping the whole thing and starting a new one, but I am so close. I know it. Here's the error:'CSHARP_UNIT5_DRAFT4.Form1.Debit(decimal)

Code:
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 CSHARP_UNIT5_DRAFT4
{
    public partial class Form1 : Form
    {
        Account account;
        Account MyCheckingAccount;
        Account MySavingsAccount;
        decimal balance;
        decimal transactionFee;
        decimal interestRate;

        public Form1()
        {
            InitializeComponent();
        }
        public class Account
        {
            private decimal accountBalance;
            public Account(decimal balance)
            {
                this.accountBalance = balance;
            }
            public Account()
            {
                accountBalance = 0;
            }
            public virtual decimal Credit(decimal amount)
            {
                return this.accountBalance += amount;
            }
            public virtual decimal Debit(decimal amount)
            {
                return this.accountBalance -= amount;
            }
            public virtual decimal getBalance()
            {
                return accountBalance;
            }
        }

        class CheckingAccount : Account
        {
            private decimal TransactionFee;
            decimal checkingBalance;

            public CheckingAccount(decimal balance, decimal TFee)
                : base(balance)
            {
                TransactionFee = TFee;
            }
            public CheckingAccount(decimal TFee)
            {
                TransactionFee = TFee;
            }
            public override decimal Credit(decimal amount)
            {
                return base.Credit(amount - TransactionFee);
            }

        }
        public override decimal Debit (decimal amount)
        {
            return base.Debit(amount + transactionFee);
        }

        class SavingsAccount : Account
        {
            private decimal interestRate;
            private decimal interest;
            public SavingsAccount(decimal balance, decimal intR)
                : base(balance)
            {
                interestRate = intR;
            }
            public SavingsAccount(decimal intR)
            {
                interestRate = intR;
            }
            public virtual decimal CalculateInterest()
            {
                interest = interestRate * base.getBalance();
                return interest;
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.comboBox1.Items.Add("Checking");
                this.comboBox1.Items.Add("Savings");
                this.comboBox1.SelectedIndex = 0;
                this.comboBox2.Items.Add("Credit");
                this.comboBox2.Items.Add("Debit");
                this.comboBox2.SelectedIndex = 0;
                this.txtAmount.Text = "0.00";
            }

            private void btnSummary_Click(object sender, EventArgs e)
            {

            }

            private void btnEnter_Click(object sender, EventArgs e)
            {
                switch (comboBox1.Text)
                {
                    case "Checking":
                        account = MyCheckingAccount;
                        break;
                    case "Savings":
                        account = MySavingsAccount;
                        break;
                }
                switch (comboBox2.Text)
                {
                    case "Credit":
                        account.Credit(decimal.Parse(txtAmount.Text));
                        break;
                    case "Debit":
                        account.Debit(decimal.Parse(txtAmount.Text));
                        break;
                }
                MessageBox.Show((balance).ToString("0.00"));
            }

            private void btnNewChecking_Click(object sender, EventArgs e)
            {
                transactionFee = decimal.Parse(txtTransaction.Text);
                balance = decimal.Parse(txtBalance.Text);
                if (balance == 0)
                {
                    MyCheckingAccount = new CheckingAccount(transactionFee);
                    MessageBox.Show("Your Checking Account has now been created with a balance of $0."
                        + "\n\n" + "Welcome to the bank of Unit 5.");
                }
                else
                {
                    MyCheckingAccount = new CheckingAccount(balance, transactionFee);
                    MessageBox.Show("Your Checking Account has now been created with a balance of $" + balance
                        + "\n\n" + "Welcome to the bank of Unit 5.");
                }
            }

            private void btnNewSaving_Click(object sender, EventArgs e)
            {
                interestRate = decimal.Parse(txtRate.Text);
                balance = decimal.Parse(txtSbalance.Text);
                if (balance == 0)
                {
                    MySavingsAccount = new SavingsAccount(interestRate);
                    MessageBox.Show("Savings account is now open. Balance is $0."
                        + "\n\n" + "Welcome to the bank of Unit 5.");
                }
                else
                {
                    MySavingsAccount = new SavingsAccount(balance, interestRate);
                    MessageBox.Show("Savings Account is now open. Balance is $" + balance);
                }
            }

            private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
            {
                string aboutString = "Programmed by: Victor E. Campudoni"
                    + "\n\n" + "For Kaplan University IT466-01."
                    + "\n\n" + "I attest that this is my own work.";
                string captionString = "Bank Account: Unit 5 assignment";
                MessageBox.Show(aboutString, captionString);
            }

            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }
}
        


Is This A Good Question/Topic? 0
  • +

Replies To: Having an Error and I just can't see why

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Having an Error and I just can't see why

Posted 21 June 2011 - 06:11 PM

What error is it giving you, as what you posted is just a line, not an error message.

This post has been edited by Momerath: 21 June 2011 - 06:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 feastfulsaint  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 15-July 10

Re: Having an Error and I just can't see why

Posted 21 June 2011 - 06:26 PM

View PostMomerath, on 21 June 2011 - 06:11 PM, said:

What error is it giving you, as what you posted is just a line, not an error message.


public override decimal [b]Debit[/b] (decimal amount)
 {
    return base.Debit(amount + transactionFee);
 }


The problem is in the override decimal Debit. The problem is that I just can't figure out why?! I am going to sleep on it an maybe after some rest I will see the problem. But thank you for the quick response.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4427
  • View blog
  • Posts: 7,696
  • Joined: 08-June 10

Re: Having an Error and I just can't see why

Posted 21 June 2011 - 07:41 PM

Again, that's just the line. What is the actual compiler error?

Never mind, I see what's going on. Your code is quite messed up. You've been declaring classes inside of classes, methods outside of the classes they belong to, and other methods inside the sub-classes rather than outside.

For what you're doing, you should not be declaring one class inside another. That's the first thing to fix. If you need to, break them out across multiple files, but make sure they're not inside of each other. Then make sure the methods are inside the correct classes. Then you'll be fine.
Was This Post Helpful? 1
  • +
  • -

#5 feastfulsaint  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 15-July 10

Re: Having an Error and I just can't see why

Posted 22 June 2011 - 04:28 PM

Thank you Curtis. After getting some much needed rest I saw the same errors. Sorry to bother everyone here. I just panicked. Again thank you for the reply.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1