Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS442: ADVANCED PROGRAMMING USING JAVA Lab 8: Inheritance Hierarchy Computer Science Department.

Similar presentations


Presentation on theme: "CS442: ADVANCED PROGRAMMING USING JAVA Lab 8: Inheritance Hierarchy Computer Science Department."— Presentation transcript:

1 CS442: ADVANCED PROGRAMMING USING JAVA Lab 8: Inheritance Hierarchy Computer Science Department

2 Lab Contents  Implementing is-a relationship.  Define constructors in sub and super classes.  Overload and override methods. 2

3 Given the following inheritance hierarchy of the Campus Community case study: 3

4 Question??.. 4  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.

5 Variables and constructors.. 5 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); }

6 Set methods … 6 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; }

7 Get methods … 7 public String getJobDescription() { return JobDescription; } public double getAllowance() { return Allowance; }

8 Compute Salary method.. 8 public double computeSalary() { return getSalary()+(getSalary()*Allowance); }

9 Override toString().. public String toString() { return "Administrator{" + super.toString() + "\nJobDescription=" + JobDescription + ", Allowance=" + Allowance + '}'; }

10 Main class.. 10 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", " ", new Date(14,6,1980),"Lecturer", 8000, new Date(12,5,2012)); System.out.println(emp);

11 Cont… dr. Amal Khalifa, Staff staff=new Staff("Malak", "Mohammed", " ", new Date(2,6,1991),"Registrar", 6000, new Date(12,10,2013), 'f'); System.out.println(staff); Administrator admin=new Administrator("Lina", "Fahd", " ", 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()); }


Download ppt "CS442: ADVANCED PROGRAMMING USING JAVA Lab 8: Inheritance Hierarchy Computer Science Department."

Similar presentations


Ads by Google