package _5_6;
public class ManagerTest {
public static void main(String[] args) {
NewEmployee e = new NewEmployee("Harry Hacker", 50000, 1989, 10, 1);
System.out.println(e.getName() + ": " + e.getSalary()); // Output the name and salary
NewManager boss = new NewManager("Carl Cracker", 80000, 1987, 12, 15);
boss.setBonus(5000); // Set bonus for the manager
System.out.println(boss.getName() + ": " + boss.getSalary()); // Output the manager's name and salary
}
}
package _5_6;
import java.util.*;
public class NewEmployee {
private String name;
private double salary;
private Date hireDay;
public NewEmployee(String n, double s, int year, int month, int day) {
name = n;
salary = s;
// Correct initialization of hireDay
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
hireDay = calendar.getTime();
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public Date getHireDay() {
return hireDay;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
}
class NewManager extends NewEmployee {
private double bonus;
public NewManager(String n, double s, int year, int month, int day) {
super(n, s, year, month, day);
bonus = 0; // Make it clear that bonus is initialized to 0
}
@Override
public double getSalary() {
double baseSalary = super.getSalary();
return baseSalary + bonus;
}
public void setBonus(double b) {
bonus = b;
}
}
3021

被折叠的 条评论
为什么被折叠?



