Bank Accounts
Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class.
• Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an Account object, should have an overdraft limit variable. Ensure that you have overridden methods of the Account class as necessary in both derived classes.
• Now create a Bank class, an object of which contains an array of Account objects. Accounts in the array could be instances of the Account class, the SavingsAccount class, or the CheckingAccount class. Create some test accounts (some of each type).
• The Bank class requires a method for opening accounts, and to deposit and withdraw from accounts specified by their account number. Account numbers are generated sequentially starting with 101.
Hints:
• Note that the balance of an account may only be modified through the deposit(double) and withdraw(double) methods.
• The Account class should not need to be modified at all. • Be
sure to test what you have done after each step.
• Use BankDemo.java to test your code.
package com.bank;
public class BankDemo
{
public static void main(String[] args)
{
Bank tinyBank = new Bank(10); // create Bank that can hold 3
accounts
tinyBank.openCheckingAccount(100,20); // balance=100 credit limit =
20
tinyBank.openSavingsAccount(200, 0.05); // balance=200
interest=5%
tinyBank.openCheckingAccount(300,30); // balance=300 credit limit =
30
tinyBank.openSavingsAccount(400,0.05); // balance=400
interest=5%);
tinyBank.openCheckingAccount(400,40); // balance=400 credit limit =
40
tinyBank.openSavingsAccount(400,0.05); // balance=400
interest=5%);
tinyBank.printAccouns();
System.out.println("\ntinyBank.deposit(112,500)");
tinyBank.deposit(112,500);
System.out.println("\ntinyBank.withdraw(101,500)");
tinyBank.withdraw(101,500);
System.out.println("\ntinyBank.withdraw(101,110)");
tinyBank.withdraw(101,110);
System.out.println("\ntinyBank.addInterest(101)");
tinyBank.addInterest(101);
System.out.println("\ntinyBank.addInterest(102)");
tinyBank.addInterest(102);
System.out.println("\ntinyBank.withdraw(102,500)");
tinyBank.withdraw(102,500);
System.out.println("\ntinyBank.withdraw(102,200)");
tinyBank.withdraw(102,200);
System.out.println();
tinyBank.printAccouns();
}
}
----------
package com.bank;
public class Account {
private double bal; // The current balance
private int accnum; // The account number
public Account(int a) {
bal = 0.0;
accnum = a;
}
public void deposit(double sum) {
if (sum > 0)
bal += sum;
else
System.out.println("Account.deposit(...): " + "cannot deposit
negative amount.");
}
public void withdraw(double sum) {
if (sum > 0)
bal -= sum;
else
System.out.println("Account.withdraw(...): " + "cannot withdraw
negative amount.");
}
public double getBalance() {
return bal;
}
public int getAccountNumber() {
return accnum;
}
public String toString() {
return "Acc " + accnum + ": " + "balance = " + bal;
}
public final void print() {
// Don't override this,
// override the toString method
System.out.println(toString());
}
public void addInterest() {
}
}
---------------
/**
*
*/
package com.bank;
/**
* @author
*
*/
public class CheckingAccount extends Account {
int overDraftLimit;
/**
* @return the overDraftLimit
*/
public int getOverDraftLimit() {
return overDraftLimit;
}
/**
* @param overDraftLimit the overDraftLimit to set
*/
public void setOverDraftLimit(int overDraftLimit) {
this.overDraftLimit = overDraftLimit;
}
public CheckingAccount(int accNum, int b, int od) {
super(accNum);
super.deposit(b);
overDraftLimit = od;
// TODO Auto-generated constructor stub
}
}
---------
/**
*
*/
package com.bank;
/**
* @author
*
*/
public class SavingsAccount extends Account {
double interest;
/**
* @return the interest
*/
public double getInterest() {
return interest;
}
/**
* @param interest the interest to set
*/
public void setInterest(double interest) {
this.interest = interest;
}
public SavingsAccount(int accNum, int balance,double interest)
{
super(accNum);
super.deposit(balance);
this.interest = interest;
// TODO Auto-generated constructor stub
}
}
----------
/**
*
*/
package com.bank;
/**
* @author
*
*/
public class Bank {
int accountNum = 100;
Account[] accounts = null;
int count = 0;
public Bank(int size) {
accounts = new Account[size];
}
public void openCheckingAccount(int i, int j) {
// TODO Auto-generated method stub
accounts[count++] = new CheckingAccount(accountNum++, i, j);
}
public void openSavingsAccount(int i, double d) {
// TODO Auto-generated method stub
accounts[count++] = new SavingsAccount(accountNum++, i, d);
}
public void deposit(int i, int j) {
// TODO Auto-generated method stub
for (int k = 0; k < count; k++) {
if (accounts[k].getAccountNumber() == i) {
accounts[k].deposit(j);
}
}
}
public void withdraw(int i, int j) {
// TODO Auto-generated method stub
for (int k = 0; k < count; k++) {
if (accounts[k].getAccountNumber() == i) {
if (accounts[k].getBalance() > j)
accounts[k].withdraw(j);
else
System.out.println("No sufficient balance");
}
}
}
public void printAccouns() {
// TODO Auto-generated method stub
for (int k = 0; k < count; k++) {
accounts[k].print();
;
}
}
public void addInterest(int i) {
// TODO Auto-generated method stub
for (int k = 0; k < count; k++) {
if (accounts[k].getAccountNumber() == i && accounts[k]
instanceof SavingsAccount) {
double bal = accounts[k].getBalance();
double intRate = ((SavingsAccount) accounts[k]).getInterest();
double intrest = bal + ((bal * intRate) / 100);
accounts[k].deposit(intrest);
}
}
}
}
-------
Output
Acc 100: balance = 100.0
Acc 101: balance = 200.0
Acc 102: balance = 300.0
Acc 103: balance = 400.0
Acc 104: balance = 400.0
Acc 105: balance = 400.0
tinyBank.deposit(112,500)
tinyBank.withdraw(101,500)
No sufficient balance
tinyBank.withdraw(101,110)
tinyBank.addInterest(101)
tinyBank.addInterest(102)
tinyBank.withdraw(102,500)
No sufficient balance
tinyBank.withdraw(102,200)
Acc 100: balance = 100.0
Acc 101: balance = 180.04500000000002
Acc 102: balance = 100.0
Acc 103: balance = 400.0
Acc 104: balance = 400.0
Acc 105: balance = 400.0
Bank Accounts Look at the Account class Account.java and write a main method in a different...
Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...
Create an Inheritance hierarchy that a bank may use to represent customer's bank accounts (Checking and Savings), this includes a GUI user interface that allows user to login, and deposit or withdraw, and application to display the transaction and final balance. All the bank customers can: - Create a new account - Deposit (Credit) money into their account and/or withdraw (debit) money from their account. - Application should expect user to login to their account using login/password Create necessary classes...
You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...
In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived...
In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...
IN JAVAThe code is attached below has the Account class that was designed to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. I need creat program using the 2 java programs.Create two subclasses for checking and savings accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.I need to write a test program that creates objects of Account,...
Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should have an interest rate that is specified in its constructor. Furthermore, there should be a method, addInterest, that deposits interest into account, based on the account balance and interest rate. Create another subclass of BankAccount named CheckingAccount. A CheckingAccount should keep track of the number of transactions made (deposits and withdrawals). Name this field transactionCount. Also, the set fee for transactions is three dollars,...
In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...
NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...
Please help JAVA
Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer...