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 checking account for each account number.Remember since accountNumber is a privatemember in BankAccount, itmust be changed through a mutator method.
Write a new instance method, withdraw, that overrides the withdraw method inthe superclass. This method should take the amount to withdraw, add to it thefee for check clearing, and call the withdraw method from the superclass.Remember that to override the method, it must have the same method heading.Notice that the withdraw method from the superclass returns true or falsedepending if it was able to complete the withdrawal or not. The method thatoverrides it must also return the same true or false that was returned from thecall to the withdraw method from the superclass.
// A new class called "SavingsAccount" that inherits from the abstract class "BankAccount". public class SavingsAccount extends BankAccount { private double rate = .025; //annual rate private int savingsNumber = 0; private String accountNumber; public SavingsAccount(String name, double begBal) { super(name, begBal); accountNumber = super.getAccountNumber() + "-" + savingsNumber; } public SavingsAccount(SavingsAccount oldAccount, double begBal) { super(oldAccount, begBal); savingsNumber = oldAccount.savingsNumber + 1; accountNumber = super.getAccountNumber() + "-" + savingsNumber; } public void postInterest( ) { //rate is an annual rate, and we only one one month's worth of interest. double newBalance = getBalance() * (1 +rate/12); setBalance(newBalance); } public String getAccountNumber( ) { return accountNumber; } }
// Class "AccountDriver" demonstrates the child classes created from the abstract class "BankAccount". import java.text.*; // to use Decimal Format public class AccountDriver { public static void main(String[] args) { double put_in = 500; double take_out = 1000; DecimalFormat myFormat; String money; String money_in; String money_out; boolean completed; // to get 2 decimals every time myFormat = new DecimalFormat("#.00"); //to test the Checking Account class CheckingAccount myCheckingAccount = new CheckingAccount("Benjamin Franklin", 1000); System.out.println ("Account Number " + myCheckingAccount.getAccountNumber() + " belonging to " + myCheckingAccount.getOwner()); money = myFormat.format(myCheckingAccount.getBalance()); System.out.println ("Initial balance = $" + money); myCheckingAccount.deposit (put_in); money_in = myFormat.format(put_in); money = myFormat.format(myCheckingAccount.getBalance()); System.out.println ("After deposit of $" + money_in + ", balance = $" + money); completed = myCheckingAccount.withdraw(take_out); money_out = myFormat.format(take_out); money = myFormat.format(myCheckingAccount.getBalance()); if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println ("Insuffient funds to withdraw $" + money_out + ", balance = $" + money); } System.out.println(); //to test the savings account class SavingsAccount yourAccount = new SavingsAccount ("William Shakespeare", 400); System.out.println ("Account Number " + yourAccount.getAccountNumber() + " belonging to " + yourAccount.getOwner()); money = myFormat.format(yourAccount.getBalance()); System.out.println ("Initial balance = $" + money); yourAccount.deposit (put_in); money_in = myFormat.format(put_in); money = myFormat.format(yourAccount.getBalance()); System.out.println ("After deposit of $" + money_in + ", balance = $" + money); completed = yourAccount.withdraw(take_out); money_out = myFormat.format(take_out); money = myFormat.format(yourAccount.getBalance()); if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println ("Insuffient funds to withdraw $" + money_out + ", balance = $" + money); } yourAccount.postInterest(); money = myFormat.format(yourAccount.getBalance()); System.out.println ("After monthly interest has been posted," + "balance = $" + money); System.out.println(); //to test the copy constructor of the savings account class SavingsAccount secondAccount = new SavingsAccount (yourAccount,5); System.out.println ("Account Number " + secondAccount.getAccountNumber()+ " belonging to " + secondAccount.getOwner()); money = myFormat.format(secondAccount.getBalance()); System.out.println ("Initial balance = $" + money); secondAccount.deposit (put_in); money_in = myFormat.format(put_in); money = myFormat.format(secondAccount.getBalance()); System.out.println ("After deposit of $" + money_in + ", balance = $" + money); secondAccount.withdraw(take_out); money_out = myFormat.format(take_out); money = myFormat.format(secondAccount.getBalance()); if (completed) { System.out.println("After withdrawal of $" + money_out + ", balance = $" + money); } else { System.out.println ("Insuffient funds to withdraw $" + money_out + ", balance = $" + money); } System.out.println(); //to test to make sure new accounts are numbered correctly CheckingAccount yourCheckingAccount = new CheckingAccount ("Isaac Newton", 5000); System.out.println ("Account Number " + yourCheckingAccount.getAccountNumber() + " belonging to " + yourCheckingAccount.getOwner()); } }
// The "BankAccount" class is an abstract class that defines any type of bank account. An abstract class is a special // type of class that is used only for inheritance purposes...objects are never directly created from it. So since the // "BankAccount" class is an abstract class, it has been given to you so you can create new classes that inherit // from it such as the "CheckingAccount" class. public abstract class BankAccount { // class variable so that each account has a unique number protected static int numberOfAccounts = 100001; // current balance in the account private double balance; // name on the account private String owner; // number bank uses to identify account private String accountNumber; //default no-arg constructor public BankAccount() { balance = 0; accountNumber = numberOfAccounts + ""; numberOfAccounts++; } //standard constructor public BankAccount(String name, double amount) { owner = name; balance = amount; accountNumber = numberOfAccounts + ""; numberOfAccounts++; } //copy constructor public BankAccount(BankAccount oldAccount, double amount) { owner = oldAccount.owner; balance = amount; accountNumber = oldAccount.accountNumber; } //Method "deposit" allows you to add money to the account public void deposit(double amount) { balance = balance + amount; } //Method "withdraw" allows you to remove money from the account if enough money //returns true if the transaction was completed //returns false if the there was not enough money public boolean withdraw(double amount) { boolean completed = true; if (amount <= balance) { balance = balance - amount; } else { completed = false; } return completed; } //accessor method to get balance public double getBalance() { return balance; } //accessor method to get owner public String getOwner() { return owner; } //accessor method to get account number public String getAccountNumber() { return accountNumber; } //mutator method to change the balance public void setBalance(double newBalance) { balance = newBalance; } //mutator method to change the account number public void setAccountNumber(String newAccountNumber) { accountNumber = newAccountNumber; } }
// Follow the instructions for Lab 9 to complete Task #1 of the lab Manual. You will be asked to create // a new class that inherits from the abstract class "BankAccount". An abstract class is a special type of // class that is used only for inheritance purposes...objects are never directly created from it. So since the // "BankAccount" class is an abstract class, it has been given to you so you can create new classes that inherit // from it such as the "CheckingAccount" class.
// Create a new
class called CheckingAccount that extends BankAccount.
public class CheckingAccount extends BankAccount
{
// It should contain a static constant FEE that represents the cost
of clearing onecheck. Set it equal to 15 cents.
public static final
double FEE =
0.15;
// Write a constructor that takes a name and an initial amount as
parameters.
public
CheckingAccount(String name,
double
initialAmount)
{
// It should call the constructor for the
superclass.
super(name, initialAmount);
// It should initialize accountNumber to be the
current value in accountNumber concatenated with -10 (All checking
accounts at this bank are identified by the extension -10). There
can be only one checking account for each account number.Remember
since accountNumber is a private member in BankAccount, it must be
changed through a mutator method.
setAccountNumber(getAccountNumber()+"-10");
}
// Write a new instance method, withdraw, that overrides the
withdraw method in the superclass. This method should take the
amount to withdraw, add to it the fee for check clearing, and call
the withdraw method from the superclass. Remember that to override
the method, it must have the same method heading.Notice that the
withdraw method from the superclass returns true or false depending
if it was able to complete the withdrawal or not. The method
thatoverrides it must also return the same true or false that was
returned from thecall to the withdraw method from the
superclass.
public boolean
withdraw(double
amount)
{
return super.withdraw(amount+FEE);
}
}
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...
According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes Account - number: int - openDate: String - name: String - balance: double + Account(int, String, String, double) + deposit(double): void + withdraw (double): boolean + transferTo(Account, double): int + toString(): String CheckingAccount + CheckingAccount(int, String, String, double) + transferTo(Account, double): int Given the above UML diagam, define Account and CheckingAccount classes as follow: Account (8 points) • public Account(int nu, String op, String...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) { CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...
Requirements: Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below. BankAccount: an abstract class. SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...
Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount. Implement four methods: • public void deposit(double amount, String account) • public void withdraw(double amount, String account) • public void transfer(double amount, String account) • public double getBalance(String account) Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is...
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...
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,...
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...
(JAVA NetBeans) Write programs in java Modify the textbook example textbook example: //BankAccount.java import java.text.DecimalFormat; public class BankAccount { public final DecimalFormat MONEY = new DecimalFormat( "$#,##0.00" ); private double balance; /** Default constructor * sets balance to 0.0 */ public BankAccount( ) { balance = 0.0; System.out.println( "In BankAccount default constructor" ); } /** Overloaded constructor * @param startBalance beginning balance */ public BankAccount( double startBalance ) { if ( balance >= 0.0 ) balance = startBalance; else balance...
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...