import java.util.Scanner;
class Faculty{
private String name;
private double salary;
public Faculty(String name, double salary) {
this.name = name;
this.salary = salary;
}
public double bonus(float percent){
return (percent/100.0)*salary;
}
// Define method getDetails()
public String getDetails() {
return name + ", " + salary;
}
// Override method getDetails(float percent)
public String getDetails(float percent) {
double b = bonus(percent);
return name + ", " + salary+ ", bonus = " + b;
}
}
class Hod extends Faculty{
private String personalAssistant;
public Hod(String name, double salary, String pa) {
super(name, salary);
this.personalAssistant = pa;
}
// Override method bonus(float percent)
// Override method getDetails()
// Override method getDetails(float percent)
// Overriding bonus: 50% less than regular faculty bonus
@Override
public double bonus(float percent) {
double regularBonus = super.bonus(percent);
return regularBonus * 0.5;
}
// Override getDetails to include personalAssistant
@Override
public String getDetails() {
return super.getDetails() + ", " + personalAssistant;
}
// Override getDetails(float percent) to include personalAssistant and bonus
@Override
public String getDetails(float percent) {
double b = bonus(percent);
return super.getDetails() + ", " + personalAssistant + ", " + b;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Faculty obj1 = new Faculty(sc.next(), sc.nextDouble());
Faculty obj2 = new Hod(sc.next(), sc.nextDouble(), sc.next());
System.out.println(obj1.getDetails());
System.out.println(obj1.getDetails(10));
System.out.println(obj2.getDetails());
System.out.println(obj2.getDetails(10));
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: