Question

In: Computer Science

Design a class named Employee. The class should keep the following information in fields: • Employee...

Design a class named Employee. The class should keep the following information in fields: • Employee name • Employee number in the format XXX–L, where each X is a digit within the range 0–9, and the L is a letter within the range A–M. • Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields to hold the following information: Shift (an integer) Hourly pay rate (a double) The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1, and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object. In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Design a ShiftSupervisor class that inherits from the Employee class. The ShiftSupervisor class should have a field that holds the annual salary, and a field that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator methods for the class. In a particular factory, a team leader is an hourly paid production worker who leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that inherits from the ProductionWorker class. The TeamLeader class should have fields for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses a TeamLeader object and a ShiftSupervisor object, as well as an Employee object. Be sure that all methods defined are called.

Solutions

Expert Solution

class Employee
{
//variables
private String name;
private String empNum;
String hiredate;


//constructor
public Employee(String name,String empNum,String hiredate)
{
this.name = name;
this.empNum = empNum;
this.hiredate = hiredate;
}
//set and get methods
public void setName(String name)
{
this.name = name;
}
public void setEmpNum(String empNum)
{
this.empNum = empNum;
}
public void setHiredate(String hiredate)
{
this.hiredate = hiredate;
}

public String getName()
{
return name;
}
public String getEmpNum()
{
return empNum;
}
public String getHiredate()
{
return hiredate;
}
public void display()
{
System.out.print("\nName: "+getName());
System.out.print("\nEmployee number: "+getEmpNum());
System.out.print("\nHire date: "+getHiredate());
}

}

class ProductionWorker extends Employee
{
private int shift;
private double hourlyPayRate;


//passing parameters to base class Employee from derived class ProductionWorker
public ProductionWorker(String name,String empNum,String hiredate,int shift,double hourlyPayRate)
{
   super(name,empNum,hiredate);
this.shift = shift;
this.hourlyPayRate = hourlyPayRate;
}
//get and set functions
public void setShift(int shift)
{
this.shift = shift;
}
public void setHouryPayRate(double hourlyPayRate)
{
this.hourlyPayRate = hourlyPayRate;
}

public double getShift()
{
return shift;
}
public double getHourlyPayRate()
{
return hourlyPayRate;
}
public void displayDetails()
{
super.display(); //call to Employee class function
System.out.print("\nShift: $"+getShift());
System.out.print("\nHourly Pay Rate : "+getHourlyPayRate());
}
}

class TeamLeader extends ProductionWorker
{
private double monthlyBonus;
private int reqTrainingHours;
private int attendedHours;

  
public TeamLeader(String name,String empNum,String hiredate,int shift,double hourlyPayRate,double monthlyBonus,int reqTrainingHours,int attendedHours)
{
   super(name,empNum,hiredate,shift,hourlyPayRate);
this.monthlyBonus = monthlyBonus;
this.reqTrainingHours = reqTrainingHours;
this.attendedHours = attendedHours;
}
//get and set functions
public void setMonthlyBonus(double monthlyBonus)
{
this.monthlyBonus = monthlyBonus;
}
public void setReqTrainingHours(int reqTrainingHours)
{
this.reqTrainingHours = reqTrainingHours;
}
void setAttendedHours(int attendedHours)
{
this.attendedHours = attendedHours;
}

public double getMonthlyBonus()
{
return monthlyBonus;
}
public int getReqTrainingHours()
{
return reqTrainingHours;
}
public int getAttendedHours()
{
return attendedHours;
}
public void displayDetails()
{
System.out.print("\nTeam leader : ");
super.display(); //call to Employee class function
System.out.print("\nMonthly Bonus : $"+getMonthlyBonus());
System.out.print("\nRequired Training Hours : "+getReqTrainingHours());
System.out.print("\nAttended Training Hours : "+getAttendedHours());
}
}
class ShiftSupervisor extends Employee
{
private double annualSalary;
double annualProductionBonus;

  
//passing parameters to base class Employee from derived classShiftSupervisor
public ShiftSupervisor(String name,String empNum,String hiredate,double annualSalary,double annualProductionBonus)
{
   super(name,empNum,hiredate);
this.annualSalary = annualSalary;
this.annualProductionBonus = annualProductionBonus;
}
//get and set functions
void setAnnualSalary(double annualSalary)
{
this.annualSalary = annualSalary;
}
public void setAnnualProductionBonus(double annualProductionBonus)
{
this.annualProductionBonus = annualProductionBonus;
}

public double getAnnualSalary()
{
return annualSalary;
}
public double getAnnualProductionBonus()
{
return annualProductionBonus;
}
public void displayDetails()
{
super.display(); //call to Employee class function
System.out.print("\nAnnual Salary: $"+getAnnualSalary());
System.out.print("\nAnnual Production Bonus: $"+getAnnualProductionBonus());
}

}


class Test
{
   public static void main (String[] args)
   {
       TeamLeader tl= new TeamLeader("Andrew Johnson","676-A","10/21/2010",1,7.8,500.50,40,25);
  
  
  
tl.displayDetails();
  
ShiftSupervisor ss = new ShiftSupervisor("John Doe","859-M","7/24/2014",75000,15000);
  
ss.displayDetails();

   }
}

Output:

Team leader : 
Name: Andrew Johnson
Employee number: 676-A
Hire date: 10/21/2010
Monthly Bonus : $500.5
Required Training Hours  : 40
Attended Training Hours : 25
Name: John Doe
Employee number: 859-M
Hire date: 7/24/2014
Annual Salary: $75000.0
Annual Production Bonus: $15000.0

Do ask if any doubt. Please upvote.


Related Solutions

Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two...
Complete the following C++ tasks: a. Design a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Create the class diagram and write the pseudocode that defines the class. b. Design an application that declares three BaseballGame objects and sets and displays their values. c. Design an application that declares an array of 12 BaseballGame objects. Prompt the user for...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Problem Statement Design a class named Car that has the following fields: year: The year field...
Problem Statement Design a class named Car that has the following fields: year: The year field is an integer that holds the car’s year. make: the make field is a String that holds the make of the car. speed: the speed field is an integer that holds the car’s current speed. In addition, the class should have the following constructor and other methods: Constructor: the constructor should accept the car’s year >model and make as parameters. These values should be...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and...
Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT