Question

/*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every...

/*Design a class BankAccount that has the following properties:
 * Account Number (should be static and increased every time an account is created.
 * An array of holders max 5 and a holder is a Person object 
 * A int to rember how many holders
 * Balance (float) 
 * Date opened 
 * interest rate
 * Constructors 
 * addHolder will add one more Person as a holder, if you reach 5 don't add. 
 * Setters getters
 * method payInterest that add interest to the accoun t
 * method Deposit(float )
 * method Withdraw(float)
 * toString() 
 * 
 */
public class BankAccount {
        
        public String toString() {
                String st = "";
                //keep adding to it whatever you need 
                
                return st;
        }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Person.java

public class Person {
   private String name;
   private int age;

   public Person(String name, int age) {
       this.name = name;
       this.age = age;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   @Override
   public String toString() {
       return "Name=" + name + ", Age=" + age;
   }

}

________________________

// BankAccount.java

import java.util.Date;

public class BankAccount {
   private static int accountNumber;
   private Person holders[] = new Person[5];;
   private int cntHolders=0;
   private float balance;
   private Date dateOpened;
   private float interestRate;

   public BankAccount(float balance, float interestRate) {
  
       this.cntHolders = 0;
       this.balance = balance;
       this.dateOpened = new Date();
       this.interestRate = interestRate;
       accountNumber = 1111;
   }

   public void addHolder(Person p) {
       if(cntHolders<holders.length)
       {
       this.holders[cntHolders] = p;
       cntHolders++;
       }
   }

   public static int getAccountNumber() {
       return accountNumber;
   }

   public Person[] getHolders() {
       return holders;
   }

   public int getCntHolders() {
       return cntHolders;
   }

   public float getBalance() {
       return balance;
   }

   public Date getDateOpened() {
       return dateOpened;
   }

   public float getInterestRate() {
       return interestRate;
   }

   public void setInterestRate(float interestRate) {
       this.interestRate = interestRate;
   }

   public void payInterest() {
       this.balance = balance + balance * (interestRate / 100);
   }

   public void deposit(float amt) {
       this.balance += amt;
   }

   public void withdraw(float amt) {
       if (balance - amt >= 0)
           this.balance -= amt;
   }
   public String toString() {
String st = "";
//keep adding to it whatever you need
for(int i=0;i<cntHolders;i++)
{
   st+="Name :"+holders[i].getName()+" Age :"+holders[i].getAge()+"\n";
st+="Account Number :"+accountNumber+"\n";
accountNumber++;
st+="Date Opened :"+dateOpened+"\n";
st+="Balance :$"+balance+"\n";
}

return st;
}

}
______________________________

// Test.java

public class Test {

   public static void main(String[] args) {
BankAccount ba=new BankAccount(50000,5);
ba.addHolder(new Person("Kane Williams",24));
ba.addHolder(new Person("James",25));
System.out.println(ba);
  

   }

}

________________________________

Output:

Name :Kane Williams Age :24
Account Number :1111
Date Opened :Sun May 26 01:56:15 IST 2019
Balance :$50000.0
Name :James Age :25
Account Number :1112
Date Opened :Sun May 26 01:56:15 IST 2019
Balance :$50000.0

______________________________Thank You

Add a comment
Know the answer?
Add Answer to:
/*Design a class BankAccount that has the following properties: * Account Number (should be static and increased every...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • 2. Write a class called ATMTransaction. This class has a variable balance and account number. It...

    2. Write a class called ATMTransaction. This class has a variable balance and account number. It has three methods, checkBalance, deposit and withdraw along with constructors getters and setters and a toString. Write a program that creates an object of this class. I should be able to deposit and withdraw from my account number based on my balance , but i shouldnt be able to change my account number. Look for loopholes in your program, test it correctly, your balance...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Define the class bankAccount to implement the basic properties of a bank account. An object of...

    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also, declare an array of 10 components of type bankAccount to process up...

  • 14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount...

    14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT