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...
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...
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...
Design a class named BankAccount to hold the following data for a bank account: Balance Number...
Design a class named BankAccount to hold the following data for a bank account: Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charges The class should have the following methods: Constructor: The constructor should accept arguments for the balance and annual interest rate. deposit: A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding 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...
C++ Question Design and implement a class that stores a list of students. Each student has...
C++ Question Design and implement a class that stores a list of students. Each student has the list of courses he/she registered for the semester. You will need a container of containers to hold this list of students. Choose the optimal container for this exercise, noting that no duplicates should be permitted. Use STL classes with iterators to navigate the list. Develop a test program, which allows options to add, remove, and list students and their associated course lists. Also...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT