1 / 11

CS442: Advanced programming using java

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??.

dianne
Download Presentation

CS442: Advanced programming using java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS442: Advanced programming using java Computer Science Department Lab 8: Inheritance Hierarchy

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

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

  4. 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.

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

  6. 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; }

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

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

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

  10. 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);

  11. 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

More Related