JAVA Imagine you are employed as a Java programmer at a bank. The bank wants to
ID: 3875941 • Letter: J
Question
JAVA
Imagine you are employed as a Java programmer at a bank. The bank wants to develop a system to store and approve loan applications. A clerk can create and view the loan application but only a manager can approve a loan.
While taking advantage of inheritance, define classes required to create the clerk and manager objects. Assume that both the objects have id, name and only manager has a bonus attributes. A loan application will require the customer name, loan amount and a flag to for approval. Make sure you have the methods to view, add and approve loans. Note: You can implement the methods to view, add and approve loan applications details by simply displaying different messages
Explanation / Answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author sambh
*/
class Employee {
private String id, name;
public Employee(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}
class Manager extends Employee {
private double bonusAttributes;
public Manager(String id, String name, double bonusAttributes) {
super(id, name);
this.bonusAttributes = bonusAttributes;
}
public double getBonusAttributes() {
return bonusAttributes;
}
public void setBonusAttributes(double bonusAttributes) {
this.bonusAttributes = bonusAttributes;
}
void approveLoan(Loan loan) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Approve loan of " + loan.getCustomerName() + " for amount $" + loan.getLoanAmount() + "? [Y/n]: ") ;
if (br.readLine().toLowerCase().charAt(0) == 'y')
loan.setApproved(true);
}
}
class Loan {
private String customerName;
private double loanAmount;
boolean approved;
public Loan(String customerName, double loanAmount) {
this.customerName = customerName;
this.loanAmount = loanAmount;
this.approved = false;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public double getLoanAmount() {
return loanAmount;
}
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}
public boolean isApproved() {
return approved;
}
public void setApproved(boolean approved) {
this.approved = approved;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.