Question

In: Computer Science

Object Design Example: Bank Account Object Implement the bank account class that stores account number and...

Object Design Example: Bank Account Object

Implement the bank account class that stores account number and the balance. It has methods to deposit and withdraw money. In addition, the default constructor sets account number to 0000 and balance 0. Other constructor should take the account number and the initial balance as parameters. Finally, the account class should have a static data member that stores how many accounts are created for a given application.

a) Draw the UML diagram

b) Write Java code to implement the bank account class

Solutions

Expert Solution

UML:

Account.java:

public class Account {
   private String accNo;
   private int balance;
   static int count;
   public Account(){
       this.accNo="0000";
       this.balance=0;
       count=count+1;
   }
   public Account(String accNo,int balance){
       this.accNo=accNo;
       this.balance=balance;
       count=count+1;
   }
   public String getAccNo() {
       return accNo;
   }
   public void setAccNo(String accNo) {
       this.accNo = accNo;
   }
   public int getBalance() {
       return balance;
   }
   public void setBalance(int balance) {
       this.balance = balance;
   }
   public void withdraw(int amount){
       this.balance=this.balance-amount;
   }
   public void deposit(int amount){
       this.balance=this.balance+amount;
   }
   public String toString(){
       return "Account No: "+this.accNo+"\nBalance: "+this.balance;
   }
}

Tester:

public class AccountTester {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Account acc=new Account();
       acc.deposit(100);
       System.out.println(acc.toString());
       acc.withdraw(20);
       System.out.println(acc.toString());
       Account acc1=new Account("1231", 200);
       System.out.println(acc1.toString());
       System.out.println("No of Accounts: "+Account.count);
      

   }

}

Expected output:



Related Solutions

13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number...
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. This class provides the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. b. 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...
: Design and implement class Radio to represent a radio object. The class defines the following...
: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or off. Set to...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
1.   Design a class, Account, that models the basic workings of a bank account. The class...
1.   Design a class, Account, that models the basic workings of a bank account. The class should perform the following tasks: a.   Save the account balance. b.   Save the number of transactions performed on the account. c.   Allow deposits to be made to the account. d.   Allow withdrawals to be taken from the account. e.   Calculate interest for the period. f.   Report the current account balance at any time. g.   Report the current number of transactions at any time The...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, 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...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title,...
TestLibrary.java Design and implement a class named Book. A book has a serial number, a title, an author, and a publisher. Create appropriate constructor(s) and accessor and mutator methods for the Book class. Add a static variable to the Book class and set its initial value to 100000000. When a new book is created, this static variable is automatically incremented by 1 and the new value is assigned as the serial number of the new book. Design and implement a...
Write in Java the following: A.  A bank account class that has three protected attributes: account number...
Write in Java the following: A.  A bank account class that has three protected attributes: account number (string), customer name (string), and balance (float). The class also has a parameterized constructor and a method public void withDraw (float amount) which subtracts the amount provided as a parameter from the balance. B. A saving account class that is a child class of the bank account class with a private attribute: penality rate (float). This class also has a parameterized constructor and a...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT