Consider class Certification with data members Id (int), name (String) , hours(int), level (String), costPerHr (double). Provide a sub class ProfessionalCertification that extends Certification. This class no additional data member. It overrides calculateFee method so that total cost is returned as product of hours and cost per hour plus 15% tax of total hours cost. o Also ProfessionalCertification implements Extendible Interface. You will also have to provide implementation of method extend(int duration). For this you need to add duration to the training hours of the certification. Write main class that includes calculateFee() and extend(int duration) method.
class Certification {
private int Id;
private String name;
private int hours;
private String level;
private double costPerHr;
public Certification() {
}
public Certification(int Id, String name, int hours, String level, double costPerHr) {
this.Id = Id;
this.name = name;
this.hours = hours;
this.level = level;
this.costPerHr = costPerHr;
}
public double calculateFee() {
return costPerHr * hours;
}
/**
* @return the id
*/
public int getId() {
return Id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
Id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the hours
*/
public int getHours() {
return hours;
}
/**
* @param hours the hours to set
*/
public void setHours(int hours) {
this.hours = hours;
}
/**
* @return the level
*/
public String getLevel() {
return level;
}
/**
* @param level the level to set
*/
public void setLevel(String level) {
this.level = level;
}
/**
* @return the costPerHr
*/
public double getCostPerHr() {
return costPerHr;
}
/**
* @param costPerHr the costPerHr to set
*/
public void setCostPerHr(double costPerHr) {
this.costPerHr = costPerHr;
}
}
interface Extendible {
void extend(int duration);
}
class ProfessionalCertification extends Certification implements Extendible {
public ProfessionalCertification() {
}
public ProfessionalCertification(int Id, String name, int hours, String level, double costPerHr) {
super(Id, name, hours, level, costPerHr);
}
/**
* It overrides calculateFee method so that total cost is returned as product of
* hours and cost per hour plus 15% tax of total hours cost.
*/
@Override
public double calculateFee() {
double fee = super.calculateFee();
return fee + 0.15 * fee;
}
@Override
public void extend(int duration) {
setHours(getHours() + duration);
}
}
class App {
public static void main(String[] args) {
}
}
Comments
Leave a comment