Answer to Question #296552 in Java | JSP | JSF for 111

Question #296552

Q. No. 02 Consider the following class Certification with following data members Id (int), name (String) , hours(int), level (String), costPerHr (double) Implementation of this class is provided on moellim. You are required to do the following  Provide a class StudentCertification that extends Certification . This class has an additional data member rebate (double) o Override the calculateFee method so that the total cost is calculated by getting the total for the training hours @costPerHr and applying the rebate (%). E.g. if the costPerHr is 200 and 50 hours training and 0.2 rebate then the calculateFee should return 10000 – 0.2 *10000 = 8000 


1
Expert's answer
2022-02-11T11:02:43-0500


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;
	}


}


class StudentCertification extends Certification {
	private double rebate;


	public StudentCertification() {
	}


	public StudentCertification(int Id, String name, int hours, String level, double costPerHr, double rebate) {
		super(Id, name, hours, level, costPerHr);
		this.rebate = rebate;
	}


	/**
	 * @return the rebate
	 */
	public double getRebate() {
		return rebate;
	}


	/**
	 * @param rebate the rebate to set
	 */
	public void setRebate(double rebate) {
		this.rebate = rebate;
	}


	/**
	 * Override the calculateFee method so that the total cost is calculated by
	 * getting the total for the training hours @costPerHr and applying the rebate
	 * (%). E.g. if the costPerHr is 200 and 50 hours training and 0.2 rebate then
	 * the calculateFee should return 10000 – 0.2 *10000 = 8000
	 */
	@Override
	public double calculateFee() {
		double fee = super.calculateFee();
		return fee - rebate * fee;
	}
}


class App {


	public static void main(String[] args) {
		StudentCertification StudentCertification = new StudentCertification(4545, "Peter", 50, "Junior", 200, 0.2);
		System.out.println("Fee: " + StudentCertification.calculateFee());


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS