Write a Java Class file for the class Account that represents a bank account. Usually, a bank account has a unique account number that is used to identify it. Your class should generate the account number automatically whenever a new account is created. The class should also store the account balance in a data member. All the data members should be declared as private. You class should provide the following methods:
1. a constructor that takes the starting balances as an input then uses it to initialize the balance data member. The constructor should generate an account number automatically and store it in the account number data member. Account numbers should be sequential starting from 20101.
2. getAccountNumber: returns the account number.
3. getBalance: returns the current account balance.
4. debitAccount: adds funds to the account. It takes the amount to be deducted as a parameter then subtracts it from the balance.
5. creditAccount: adds funds to the account. It takes the amount to be credited as a parameter then adds it to the balance.
6. transferFunds: transferfunds from the account to another account. It has two parameter, the Account object of the account to which the transfer is made and the amount to be transferred.

Recommended Answers

All 2 Replies

Hmm really nice question .. but where is the answer OR an ATTEMPT?

sorry here is my attempt:

import java.util.*;

public class Account1
{
    private int AccountNumber;
    private double Balance;
    private double debitAccount;
    private double creditAccount;
    private double transferFunds;
//constructor
    public Account1()
    {
        int AccountNumber;
        double Balance;
        double debitAccount;
        double creditAccount;
        double transferFunds;
    }
//-----------------------------------------------
//initilization
    public void initialize(int acctnum, double bal )
    {
        AccountNumber = acctnum;
        Balance = bal;
    }
//-----------------------------------------------
//defining methods
//selecting an account
        public int getAccountNumber()
        {
            return AccountNumber;
        }
//-----------------------------------------------
//checking account balance
        public double getBalance()
        {
            return Balance;
        }
//-----------------------------------------------
//withdraw from account
        public double debitAccount( double b )
        {
             Balance -= b;              //debits from the balance
             return Balance;
        }
//-----------------------------------------------
//deposit to account
        public double creditAccount( double b )
        {
            Balance += b;               //credits to balance
            return Balance;
        }
//-----------------------------------------------
//transferring funds
        public void transferFunds( int AccountNumber, double b )
        {
             b -= Balance;
        }
//-----------------------------------------------
//display status
    public void displayStatus()
    {
        System.out.println("Checkings Account Balance: " +Balance);
        System.out.println("Savings Account Balance: "+Balance);
        System.out.println("Money Market Balance: " +Balance);
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.