Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Create a project named BankAccountTester. Create a class named BankAccount. A bank account has fields for a balance. The bank account balance should be initialized to 0. The bank account class should include a deposit which adds an amount passed to it to the balance and a withdraw which subtracts the amount.

What I have tried:

using System;


namespace Banking
{
    public static void Main(string []args)
    { }

 //A bank account has a balance
    //that can be changed with 
    // withdraw or deposit.
    public class BankAccount
    {
        private double balance;
        //constructs a bank account 
        // with zero balance
        public BankAccount()
        {
            balance = 0;
        }
        //Constructs a bank account
        //with a given balance 
        //(initalBalance)
        public BankAccount(double initialBalance)
        {
            balance = initialBalance;
        }
        //Deposits money into the bank account.
        //(amount the amount to deposit)
        public void Deposit(double amount)
        {
            double newBalance = balance + amount;
            balance = newBalance;
        }
        //Withdraws money from the bank account
        //(the amount to withdraw)
        public void Withdraw(double amount)
        {
            double newBalance = balance - amount;
            balance = newBalance;
        }
        //Gets the current balance of the bank account.
        //(returns the current balance)
        public double GetBalance()
        {
            Console.ReadLine();
            return balance;
        }
    }
}
Posted
Updated 21-Jul-18 11:38am

1 solution

You need to move this line

C#
public static void Main(string []args)
    { }

Into the
C#
public class BankAccount
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900