PLEASE ADVISE IN WHICH IDE YOU CODED BECAUSE I AM GOING TO COPY AND PASTE THE CO
ID: 3711664 • Letter: P
Question
PLEASE ADVISE IN WHICH IDE YOU CODED BECAUSE I AM GOING TO COPY AND PASTE THE CODE IN THE SAME PROGRAM YOU'RE USING.
Design an abstract 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 deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.
withdraw: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.
calcInterest: A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:
Monthly Interest Rate = (Annual Interest Rate/12)
Monthly Interest = Balance * Monthly Interest Rate
Balance = Balance + Monthly Interest
monthlyProcess: A method that subtracts the monthly service charges from the balance, calls the calcInterest method, and then sets the variable that hold the number of withdrawals, number of deposits and monthly service charge to zero.
Next, design a SavingAccount class that is a subclass of the BankAccount class. The SavingAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below$25, it becomes inactive. (The status field could be a Boolean variable.) No more withdrawals can be made until the balance is raised above $25, at which time the account becomes active again. The savings account class should have the following methods:
withdraw: A method that determines whether the account is inactive before a withdrawal is made. No withdrawal will be allowed if the account is not active. A withdrawal is then made by calling the super-class version of the method.
deposit: A method that determines whether the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. The deposit is then made by calling the super-class version of the method.
monthlyProcess: Before the super-class method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is added to the super-class fields that holds the monthly service charges. (Don’t forget the check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)
Now write driver class to demo/test your code of the BankAccount and SavingAccount. Display the result via the standard output screen and file output as well.
The last part is to design and create a Graphical User Interface (GUI) to test those method/behaviors of the BankAccount, SavingAccount classes.
Explanation / Answer
BankAccount.java
public abstract class BankAccount
{
private double balance;
private int num_deposits;
private int num_withdraws;
private double annualInterest;
private double serviceCharges;
public BankAccount
(double balance, double annualInterest)
{
this.balance = balance;
this.annualInterest = annualInterest;
this.num_deposits = 0;
this.num_withdraws = 0;
this.serviceCharges = 0;
}
public void deposit(double amount)
{
balance += amount;
num_deposits++;
}
public void withdraw(double amount)
{
balance -= amount;
num_withdraws++;
}
public void calcInterest()
{
double monthlyInterestRate =
(annualInterest / 12);
double monthlyInterest = this.balance *
monthlyInterestRate;
balance += monthlyInterest;
}
public void monthlyProcess()
{
balance -= serviceCharges;
calcInterest();
num_deposits = 0;
num_withdraws = 0;
serviceCharges = 0;
}
public double getBalance()
{
return balance;
}
public void setBalance(double balance)
{
this.balance = balance;
}
public int getNum_deposits()
{
return num_deposits;
}
public void setNum_deposits(int num_deposits)
{
this.num_deposits = num_deposits;
}
public int getNum_withdraws()
{
return num_withdraws;
}
public void setNum_withdraws(int num_withdraws)
{
this.num_withdraws = num_withdraws;
}
public double getAnnualInterest()
{
return annualInterest;
}
public void setAnnualInterest(double annualInterest)
{
this.annualInterest = annualInterest;
}
public double getServiceCharges()
{
return serviceCharges;
}
public void setServiceCharges(double serviceCharges)
{
this.serviceCharges = serviceCharges;
}
}
SavingsAccount.java
public class SavingsAccount extends BankAccount {
private boolean status;
public SavingsAccount(double balance, double annualInterest)
{
super(balance, annualInterest);
if (balance >= 25)
{
status = true;
}
else
{
status = false;
}
}
public void withdraw(double amount)
{
if (status)
{
super.withdraw(amount);
if(super.getBalance()<25)
status = false;
}
else
{
System.out.println("Amount cannot be" + " withdrawn.");
}
}
public void deposit(double amount)
{
if (!status)
{
double avail = super.getBalance() + amount;
if (avail >= 25)
{
status = true;
}
}
super.deposit(amount);
}
public void monthlyProcess()
{
int countWithdraws = super.getNum_withdraws();
if (countWithdraws > 4)
{
super.setServiceCharges(countWithdraws - 4);
super.monthlyProcess();
if (super.getBalance() < 25)
status = false;
}
}
public boolean isStatus()
{
return status;
}
public void setStatus(boolean status)
{
this.status = status;
}
}
BankSavingAccountDemo.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class BankSavingAccountDemo {
public static void main(String args[])
{
File file = new File("out.txt"); //Your file FileOutputStream fos;
try {
fos = new FileOutputStream(file);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
SavingsAccount sa = new SavingsAccount(40, 1.5);
System.out.println("Initial account balance is:" + " $"+sa.getBalance());
printStatus(sa.isStatus());
System.out.println(" Withdraw an amount of " + "$20");
sa.withdraw(20.00);
System.out.println("Balance after withdraw: " + sa.getBalance());
printStatus(sa.isStatus());
System.out.println(" Deposit an amount of $3");
sa.deposit(3.00);
System.out.println("Balance after deposit: " + sa.getBalance());
printStatus(sa.isStatus());
System.out.println(" Withdraw an amount of " + "$10");
sa.withdraw(10.00);
System.out.println("Balance after withdraw: " + sa.getBalance());
printStatus(sa.isStatus());
System.out.println(" Deposit an amount of" + " $25");
sa.deposit(25.00);
System.out.println("Balance after deposit: " + sa.getBalance());
printStatus(sa.isStatus());
sa.monthlyProcess();
System.out.println(" Balance at end of the" + " month: ");
System.out.println("Balance in the account: " + sa.getBalance());
printStatus(sa.isStatus());
System.out.println("Number of deposits made" + ": "+sa.getNum_deposits());
System.out.println("Number of withdrawals" + " made: "+sa.getNum_withdraws());
System.out.println("Monthly charges: " + sa.getServiceCharges());
}
public static void printStatus(boolean status)
{
if(status)
System.out.println("Status of the " + "account is: ACTIVE");
else
System.out.println("Status of the " + "account is: INACTIVE");
}
}
Output from Console Standard output:
Initial account balance is: $40.0
Status of the account is: ACTIVE
Withdraw an amount of $20
Balance after withdraw: 20.0
Status of the account is: INACTIVE
Deposit an amount of $3
Balance after deposit: 23.0
Status of the account is: INACTIVE
Withdraw an amount of $10
Amount cannot be withdrawn.
Balance after withdraw: 23.0
Status of the account is: INACTIVE
Deposit an amount of $25
Balance after deposit: 48.0
Status of the account is: ACTIVE
Balance at end of the month:
Balance in the account: 48.0
Status of the account is: ACTIVE
Number of deposits made: 2
Number of withdrawals made: 1
Monthly charges: 0.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.