110 likes | 283 Views
CS442: Advanced programming using java. Lab 8: Inheritance Hierarchy. Lab Contents. Implementing is-a relationship . Define constructors in sub and super classes . Overload and override methods. Given the following inheritance hierarchy of the Campus Community case study:. Question??.
E N D
CS442: Advanced programming using java Computer Science Department Lab 8: Inheritance Hierarchy
Lab Contents • Implementing is-a relationship. • Define constructors in sub and super classes. • Overload and override methods.
Given the following inheritance hierarchy of the Campus Community case study:
Question??.. • Implement the Administrator class based on the following properties: • Job description :String • Administrative Allowance as a percentage of the basic salary (should be between 0.0 and 1.0) • Your class should also define a method Compute salary.
Variables and constructors.. • Defined variables and constructors: public class Administrator extends Faculty { private String JobDescription; private double Allowance; //between 0.0 and 1.0 public Administrator(String FName, String LName, String ssn, Date dob, String title, double salary, Date hireDate, String degree, String specality, String jobDescription, double allowance1) { super(FName, LName, ssn, dob, title, salary, hireDate, degree, specality); this.JobDescription=jobDescription; setAllowance(allownce1); }
Set methods … public void setJobDescription(String jobDescription) { this.JobDescription=jobDescription; } public void setAllowance(double allowance) { If (allownce>0 && allownce<=1) this.Allowance=allowance; Else Allownce=0.0; }
Get methods … public String getJobDescription() { return JobDescription; } public double getAllowance() { return Allowance; }
Compute Salary method.. public double computeSalary() { return getSalary()+(getSalary()*Allowance); }
Override toString().. @Override public String toString() { return "Administrator{" + super.toString() + "\nJobDescription=" + JobDescription + ", Allowance=" + Allowance + '}'; }
Main class.. public class CommunityMemberTest { public static void main(String[] args) { Student student = new Student("Mona", "Ahmed","222222",new Date(2,4,1998),"CS222222","Compuers",2); System.out.println(student); Employee emp=new Employee("Nadia", "Faisal", "144000000", new Date(14,6,1980),"Lecturer", 8000, new Date(12,5,2012)); System.out.println(emp);
Cont… Staff staff=new Staff("Malak", "Mohammed", "122000000", new Date(2,6,1991),"Registrar", 6000, new Date(12,10,2013), 'f'); System.out.println(staff); Administrator admin=new Administrator("Lina", "Fahd", "167000000", new Date(2,6,1976),"Assistant Professor", 20000, new Date(9,10,2009), "PhD", "Computer Sciences", "Head of Computer Sciences Dept", 0.2); System.out.println(admin); System.out.println(admin.getFullName()+" Full Salary: "+admin.computeSalary()); } } dr. Amal Khalifa, 2014