please rewrite this code as Pseudo-Code,.. basically rewrite the code but in eng
ID: 3817620 • Letter: P
Question
please rewrite this code as Pseudo-Code,.. basically rewrite the code but in english language , Thank you so much!
public abstract class BankAccount
{
//declare the required class variables
private double balance;
private int num_deposits;
private int num_withdraws;
private double annualInterest;
private double serviceCharges;
//constructor that takes two arguments
// one is to initialize the balance and other
// to initialize the annual interest rate
public BankAccount(double balance, double annualInterest)
{
this.balance = balance;
this.annualInterest = annualInterest;
this.num_deposits = 0;
this.num_withdraws = 0;
this.serviceCharges = 0;
}
//deposit() that accepts an argument to deposit
//The amount. Adds the amount to the available
//balance and increments num_deposits value
public void deposit (double amount)
{
balance+= amount;
num_deposits++;
}
//Withdraws() that accepts an argument to withdraws
//the amount. deducts the amount form the available balance
// and increments num_withdraws value
public void withdraw(double amount)
{
balance -= amount;
num_withdraws++;
}
//calcinterest() that calculates the monthly interest from the balance
// amount and adds the interest to the balance
public void calcInterest()
{
double monthlyInterestRate = (annualInterest / 12);
double monthlyInterest = this.balance * monthlyInterestRate;
balance += monthlyInterest;
}
//monthlyProcess() detects the monthly service charges from the
//balance and updates the balance by calling calcinterest() and sets the
//num_deposit, num_withdraws, monthly service charge variables to zero
public void monthlyProcess()
{
balance -= serviceCharges;
calcInterest();
num_deposits = 0;
num_withdraws = 0;
serviceCharges = 0;
}
// getter and setter method for balance
public double getBalance()
{
return balance;
}
public void setBallance(double balance)
{
this.balance = balance;
}
//getter and setter method for num_deposit
public int getNum_deposits()
{
return num_deposits;
}
public void setNum_deposits(int num_deposits)
{
this.num_deposits = num_deposits;
}
//getter and setter method for num_withdraws
public int getNum_withdraws()
{
return num_withdraws;
}
public void setNum_withdraws(int num_withdraws)
{
this.num_withdraws = num_withdraws;
}
//getter and setter for annualInterest
public double getAnnualInterest()
{
return annualInterest;
}
public void setAnnualInterest(double annualInterest)
{
this.annualInterest = annualInterest;
}
//getter and setter method for serviceCharges
public double getServiceCharges()
{
return serviceCharges;
}
public void setServiceCharges(double serviceCharges)
{
this.serviceCharges = serviceCharges;
}
}
======================================================================================
public class SavingsAccount extends BankAccount
{
//declare a class member which hold status of the account
private boolean status;
//constructor
public SavingsAccount(double balance, double annualInterest)
{
//initialize the super class constructor
super(balance, annualInterest);
//if the initial balance is above 25,
//set the active status to true
if (balance >= 25)
{
status = true;
}
else
{
status = false;
}
}
//withdraw() this method checks for whether the account is active
//or inactive, if the account is active, call the superclass
//withdraw method, else, do nothing
public void withdraw(double amount)
{
if(status)
{
super.withdraw(amount);
if(super.getBalance()<25)
status = false;
}
else
{
System.out.println("Amount cannot be withdrawn");
}
}
//deposit() this method checks for whether the account is active
//or inactive. if the account is inactive, check whether the
//amount to be added makes the status to active or not. if it is,
//then add the amount and set the status to active.
public void deposit(double amount)
{
if(!status)
{
double avail = super.getBalance()+ amount;
if(avail>= 25)
{
status = true;
}
}
super.deposit(amount);
}
//monthlyProcess() first it checks for the number of withdraws
//are greater than 4 or not, if the number of deposits are more
//than 4 then set the service charges to 1$ for each withdraw for
//which withdraws are above 4. at the same time check for balance.
//if it is falling less than $25 the set the status to inactive
public void monthlyProcess()
{
int countWithdraws = super.getNum_withdraws();
if(countWithdraws > 4)
{
super.setServiceCharges(countWithdraws - 4);
super.monthlyProcess();
if(super.getBalance() < 25)
status = false;
}
}
//getter and setter for the status
public boolean isStatus()
{
return status;
}
public void setStatus(boolean status)
{
this.status = status;
}
}
========================================================================
public class BankSavingAccountDemo
{
//main method
public static void main (String args[])
{
//Create an object of the savingsAccount by passing
//initial value
SavingsAccount sa = new SavingsAccount(40, 1.5);
//Display the initial amount and its value
System.out.println("initial account balance is $"+ sa.getBalance());
printStatus(sa.isStatus());
//Withdraw an amount of 20$ and then print the details
System.out.println(" Withdraw an amount of $20");
sa.withdraw(20.00);
System.out.println("Balance after withdraw: "+ sa.getBalance());
printStatus(sa.isStatus());
//Deposit an amount of 3$ and then print the details
System.out.println(" Deposit an amount of 3$");
sa.deposit(3.00);
System.out.println("Balance after deposit: "+ sa.getBalance());
printStatus(sa.isStatus());
//Withdraw an amount of 10$ and then print details
System.out.println(" Withdraw an amount of $10");
sa.withdraw(10.00);
System.out.println("Balance after withdraw is: "+ sa.getBalance());
printStatus(sa.isStatus());
//Deposit an amount of $25 and the print the details
System.out.println(" Deposit an amount of $25");
sa.deposit(25.00);
System.out.println("Balance after deposit: "+ sa.getBalance());
printStatus(sa.isStatus());
//Call the monthly process, in order to set the amount with
//interest and service charges
sa.monthlyProcess();
System.out.println(" Balance at the 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_withdraws());
System.out.println("Monthly charges: "+ sa.getServiceCharges());
}
//printStatus() that accepts a boolean argument and prints the status
//of the account depending on the boolean value
public static void printStatus(boolean status)
{
if(status)
System.out.println("Status of the account is: <>");
else
System.out.println("Status of the account is: <>");
}
}
Explanation / Answer
//Pseudo code for class BankAccount is here
create a abstract class named as BankAccount
Begins class BankAccount
Declare private variable of double type named balance
Declare private variable of int type named num_deposits
Declare private variable of int type named num_withdraws
Declare private variable of double type named annualInterest
Declare private variable of double type named serviceCharges
parameterised constructor to initialize variable balance and annualInterest
Define a method as public void deposit(double amount) add amount in balance and increment the num_deposits by one
Define a method as public void withdraw(double amount) for withdrow by deductin from balance and increment num_withdraws by one
Define a method as public void calcInterest() to calculate interest as below
monthlyInterestRate = (annualInterest / 12)
monthlyInterest = this.balance * monthlyInterestRate
balance += monthlyInterest;
End of method calcInterest
Define a method as public void monthlyProcess() for monthly process as below
balance -= serviceCharges
call the method calcInterest
initialize num_deposits by 0
initialize num_withdraws by 0
initialize serviceCharges by 0
End of method monthlyProcess
Define methods to get and set the value for the all variables
End of class BankAccount
====================================================================================
//Pseudo code for concrete class SavingsAccount
Create a concrete class named SavingsAccount by extends BankAccount
Begins class SavingsAccount
//declare a class member which hold status of the account
private variable named status type boolean
contructor begins wiith variable balance and annualInterest
call super constructor with these arguments balance and annualInterest
//if the initial balance is above 25,
//set the active status to true
start of withdraw
Override withdraw method make it specific as below
check status if true call super class method withdraw and update status
else display message "Amount cannot be withdrawn"
end of withdraw
start of deposit
Override deposit method with below logic
//deposit() this method checks for whether the account is active
//or inactive. if the account is inactive, check whether the
//amount to be added makes the status to active or not. if it is,
//then add the amount and set the status to active.
end od deposit
start of monthlyProcess
Override method monthlyProcess with logic
//monthlyProcess first it checks for the number of withdraws
//are greater than 4 or not, if the number of deposits are more
//than 4 then set the service charges to 1$ for each withdraw for
//which withdraws are above 4. at the same time check for balance.
//if it is falling less than $25 the set the status to inactive
end of monthlyProcess
//getter and setter for the status named as getStatus, setStatus
End of class SavingsAccount
============================================================================
//Pseudo code for concrete class SavingsAccount
Create a concrete class named BankSavingAccountDemo for demo
begins BankSavingAccountDemo
begins main method
Create an object of the savingsAccount by passing
initial value
Display the initial amount and its value
Withdraw an amount of 20$ and then print the details
Deposit an amount of 3$ and then print the details
Withdraw an amount of 10$ and then print details
Deposit an amount of $25 and the print the details
Call the monthly process, in order to set the amount with
interest and service charges
Ends main method
Define a method called printStatus as public static void printStatus(boolean status)
begins printStatus
printStatus() that accepts a boolean argument and prints the status
of the account depending on the boolean value
ends printStatus
Ends class BankSavingAccountDemo
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.