3.Write an Employee class that keeps data attributes for the following pieces of
information:
a.Employee name
b.Employee number
Next,write a class named ProductionWorker that is a subclass of the Employee class.
The Production Worker class should keep data attributes for the following information:
c.Shiftnumber(an integer,such as 1 for morning shift,2 for evening shift)
d.Hourly payrate
Write the appropriate accessor and mutator methods for each class.
class Employee{
private String name;
private String number;
/**
* Constructor
* @param name
* @param number
*/
public Employee(String name,String number){
this.name=name;
this.number=number;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the number
*/
public String getNumber() {
return number;
}
/**
* @param number the number to set
*/
public void setNumber(String number) {
this.number = number;
}
}
class ProductionWorker extends Employee{
//Shiftnumber(an integer,such as 1 for morning shift,2 for evening shift)
private int shiftnumber;
//Hourly payrate
private double hourlyPayrate;
/**
* Constructor
* @param name
* @param number
* @param shiftnumber
* @param hourlyPayrate
*/
public ProductionWorker(String name,String number,int shiftnumber,double hourlyPayrate) {
super(name, number);
this.shiftnumber=shiftnumber;
this.hourlyPayrate=hourlyPayrate;
}
/**
* @return the shiftnumber
*/
public int getShiftnumber() {
return shiftnumber;
}
/**
* @param shiftnumber the shiftnumber to set
*/
public void setShiftnumber(int shiftnumber) {
this.shiftnumber = shiftnumber;
}
/**
* @return the hourlyPayrate
*/
public double getHourlyPayrate() {
return hourlyPayrate;
}
/**
* @param hourlyPayrate the hourlyPayrate to set
*/
public void setHourlyPayrate(double hourlyPayrate) {
this.hourlyPayrate = hourlyPayrate;
}
}
public class Q197747 {
public static void main(String[] args) {
ProductionWorker productionWorker=new ProductionWorker("Mary Clark", "C12464654", 1, 15);
System.out.println("Name: "+productionWorker.getName());
System.out.println("Number: "+productionWorker.getNumber());
System.out.println("Shift number: "+productionWorker.getShiftnumber());
System.out.println("Hourly pay rate: "+productionWorker.getHourlyPayrate());
}
}
Comments
Leave a comment