Lab 9
Lab 9
Then use static variable counter to get unique roll numbers as follows:
The information know about each employee is his/her first name, last name and national identity card
number. The reset depends on the type of employee.
Step
by Step Guidelines
Being the base class, Employee class contains the common behavior. Add firstName, lastName
and CNIC as attributes of type String
Provide getter & setters for each attribute
Write default & parameterized constructors
Override toString() method as shown below
public String toString( ) {
return firstName + “ ” + lastName + “ CNIC# ” + CNIC ;
}
Extend this class form CommissionEmployee class not from Employee class. Why? Think on
it by yourself
Add baseSalary as an attribute of type double
Provide getter & setters for these attributes. Make sure that baseSalary never sets to negative value.
Write default & parameterize constructor. Don’t forget to call default & parameterize
constructors of Employee class.
Override toString() method as shown below
public String toString( ) {
return “\nBase plus Commission employee: ” + super.toString();
}
System.out.println(thirdEmployee);
// performing downcasting to access & raise base salary
BasePlusCommissionEmployee currentEmployee =
(BasePlusCommissionEmployee) thirdEmployee;
currentEmployee.setBaseSalary(1.10 * oldBaseSalary);
System.out.println("new base salary with 10% increase is:"+
currentEmployee.getBaseSalary());
System.out.println(thirdEmployee.earnings() );
System.out.println(fourthEmployee);
System.out.println(fourthEmployee.earnings() );
} // end main
} // end class