Based on the code below, please make a Javadocs(not generated by eclipse) that w
ID: 3817622 • Letter: B
Question
Based on the code below, please make a Javadocs(not generated by eclipse) that will describe each field and method of a class, its diffrent from pseudo code, it should be a list that's written into a word document and numbered. each method, attribute, etc should have a discription underneath it and labled by number, not comments in the code. 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: <<ACTIVE>>");
else
System.out.println("Status of the account is: <<INACTIVE>>");
}
}
Explanation / Answer
Documentation :-
BankAccount Class
Fields:
1. balance
- variable of type “double precision” and access specifier “private”
2. num_deposits
- variable of type “integer” and access specifier “private”
3. num_withdraws
- variable of type “integer” and access specifier “private”
4. annualInterest
- variable of type “double precision” and access specifier “private”
5. serviceCharges
- variable of type “double precision” and access specifier “private”
Methods:
1. Special method - Constructor
BankAccount(double balance, double annualInterest)
- Initializes the fields of BankAccount class with the arguments passed.
2. public void deposit(double amount)
- Accepts an argument to deposit the amount. Adds the amount to the available balance and increments num_deposits value
- access specifier is “public” and return type is “void”
3. public void withdraw(double amount)
- Accepts an argument to withdraws the amount. Deducts the amount form the available balance and increments num_withdraws value.
- access specifier is “public” and return type is “void”
4. public void calcInterest()
- calcinterest() that calculates the monthly interest from the balance amount and adds the interest to the balance.
- access specifier is “public” and return type is “void”
5. public void monthlyProcess()
- 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.
- access specifier is “public” and return type is “void”
6. Getter and Setter methods for balance field
a) public double getBalance()
- Returns the double precision value of balance field to calling function
b) public void setBallance(double balance)
- Assigns the double precision value to the balance field
7. Getter and Setter method for num_deposit field
a) public int getNum_deposits()
- Returns the integer value of num_deposit field to calling function
b) public void setNum_deposits(int num_deposits)
- Assigns the integer value to the num_deposit field
8. Getter and Setter method for num_withdraws field
a) public int getNum_ withdraws()
- Returns the integer value of num_ withdraw field to calling function
b) public void setNum_ withdraws(int num_withdraws)
- Assigns the integer value to the num_withdraws field
9. Getter and Setter method for annualInterest field
a) public double getAnnualInterest()
- Returns the double precision value of annualInterest field to calling function
b) public void setAnnualInterest(double annualInterest)
- Assigns the double precision value to the annualInterest field
10. Getter and Setter method for serviceCharges field
a) public double getServiceCharges()
- Returns the double precision value of serviceCharges field to calling function
b) public void setServiceCharges(double serviceCharges)
- Assigns the double precision value to the serviceCharges field
SavingsAccount class –
This class is extended from BankAccount class.
Fields:
1. status
- type is boolean, holds value true or false, access specifier is private
- holds status of account
Methods:
1. Constructor
public SavingsAccount(double balance, double annualInterest)
- Initializes the super class (BankAccount class) constructor.
- if the initial balance is above 25, set the active status to true
2. Getter and Setter for the status
public boolean isStatus()
- returns boolean value for status
public void setStatus(boolean status)
- assigns boolean value for status
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.