Overview For this assignment, you will be designing a class that represent a Ban
ID: 3595005 • Letter: O
Question
Overview For this assignment, you will be designing a class that represent a Bank Account object and banking activities. Each Bank Account object has only 3 instance variables: an id, checking balance and Saving balance. This Bank account class represents a regular account Project Specification Your Class BankAccount must include the following constructors and methods. Description Default censtructior, scts the id to, and balances to 0 Methods& Constructers BankAccount nitID, double t (String Constructs a Bank Account object given the id as a String, and holances for chocking saving as doubles initchecking, initsaving rivate String getIDAccess this accounts unique identifier. lic double this account's current balance in checking account tChecking lic double getSaving ( this account's curent balance in saving accourt Returns total balance of checking and saving lic void setID String Sets the id lic void Credit this account's chocking by depositAmount, if deposit it (depositamount) amount is negative or zero the balance will not change Debit this account's chocking balance by withdrawAmouns if in is positive and not greater than this accounf's current balance. It returns true if Owidraw AmountExplanation / Answer
/**
* The java class BankAccount that represents
* BankAccount class
* */
//BankAccount.java
import java.text.DecimalFormat;
public class BankAccount {
private String id;
private double checkingBalance;
private double savingsBalance;
//constructor to set default values
public BankAccount() {
id="???";
checkingBalance=0;
savingsBalance=0;
}
//constructot to set parameter values
public BankAccount(String initID,double initChecking,
double initSaving) {
id="???";
id=initID;
checkingBalance=initChecking;
savingsBalance=initSaving;
}
public String getID(){
return id;
}
public double getChecking(){
return checkingBalance;
}
public double getSaving(){
return savingsBalance;
}
//Return total balance of BankAccount
public double getBalance(){
return (checkingBalance+savingsBalance);
}
public void setID(String name){
id=name;
}
//Deposit method
public void deposit(double depositAmount){
if(depositAmount>0)
checkingBalance+=depositAmount;
}
//Withdraw method
public boolean withdraw(double withdrawAmount){
if(getBalance()>withdrawAmount && withdrawAmount>0)
{
checkingBalance=checkingBalance-withdrawAmount;
return true;
}
return false;
}
//Adding interest amount to checking and savings balance
public void addInterest(){
if(getBalance()<=1000)
{
checkingBalance=checkingBalance+checkingBalance*0.025;
savingsBalance=savingsBalance+savingsBalance*0.025;
}
else if(getBalance()>1000 && getBalance()<=5000)
{
checkingBalance=checkingBalance+checkingBalance*0.025;
savingsBalance=savingsBalance+savingsBalance*0.025;
}
else
{
checkingBalance=checkingBalance+checkingBalance*0.045;
savingsBalance=savingsBalance+savingsBalance*0.045;
}
}
//Checking if id of account is equal
public boolean equls(String id)
{
return id.equals(id);
}
//Override toString
public String toString() {
DecimalFormat df=new DecimalFormat("00.00");
return String.format("ID: %s Checking Balance $:%f Savings Balance $: %f",
id,checkingBalance,savingsBalance);
}
}//end of BankAccount class
Note : Please note that you have given Assignment5.java as image file.
So check with BankAccount.java class with the Assignment5.java soruce code text file with you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.