ทำการบ้านต่อไม่เป็นแล้วค่ะ ใครก็ได้ช่วยที
ตอนนี้สร้าง class employee เสร็จแล้วคือ public class Employee { /** Creates a new instance of Employee */ public Employee() { } public Employee(String name, double salary, String location) { this.name = name; this.salary = salary; this.location = location; } public String getName() { return name; } public double getSalary() { return salary; } public String getLocation() { return location; } public void raiseSalary(double pct) { salary *= (1+pct); } public String toString() { return "Name : " + name + " , Salary : " + salary + " , Location : " + location; } public static void main(String[] args) { Employee a = new Employee("Kitty",250000,"Bangkok"); Employee b = new Employee("Henry",125000,"China"); System.out.println(a); System.out.println(b); } private String name; double salary; private String location; }
และสร้าง class manager คือ public class Manager extends Employee{ /** Creates a new instance of Manager */ public Manager() { } public Manager(String name, double salary, String location) { super(name, salary, location); } public double getSalary() { return (super.getSalary()*12)+bonus; } public void setBonus(double bonus) { this.bonus = bonus; } public String toString() { return super.toString()+" Annual Salary + Bonus : " + getSalary(); } public static void main(String[] args) { Manager c = new Manager("LaLa",400000,"USA"); Manager d = new Manager("LuLu",500000,"England"); c.setBonus(100000); d.setBonus(250000); System.out.println(c); System.out.println(d); } private double bonus; } แต่ตอนนี้ มันมีโจทย์ให้ทำต่อค่ะ ทำไม่เป็นแล้ว ช่วยทำต่อให้ทีนะคะ จนปัญญาจริงๆ 1. create array of Employee in a test class and add Employee and Manager object to the array 2. use instanceof operator to check the type of the object and cast it to restore full feathers 3. create array of Manager and add Employee and Manager object to the array 4.add Employee and Manager object to the ArrayList 5.Raise everyone's salary ใครก็ได้ช่วยทีค่ะ .. ต้องส่งก่อนพรุ่งนี้ด้วยอะ :~~~~
|