Download presentation
Presentation is loading. Please wait.
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", " ", new Date(14,6,1980),"Lecturer", 8000, new Date(12,5,2012)); System.out.println(emp);
11
Cont… System.out.println(staff);
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()); } dr. Amal Khalifa, 2014
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.