The files Firmjava Staffjava StaffMemberjava Volunteerjava E

The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 – 9.7 in the text. The program illustrates inheritance and polymorphism. In this exercise you will add two more employee types to the class hierarchy (see Figure 9.1 in the text). One of the new employee types will be an Intern, but earns a commission on sales. Hence the class, which we\'ll name CommissionIntern, will be derived from the Volunteer class. The second employee type will also be an Intern but is not paid, named FreeIntern.

--Write a class named CommissionIntern with the following features:

It extends the Volunteer class.

It will have an additional instance variable (in addition to those inherited) named commission_Rate for the employee (the commission rate will represent the percent (in decimal form) that the employee earns on sales (so .25 would mean the employee earns 25% commission on sales)).

You may want to create an additional instance variable to keep track of the total sales earned.

The constructor takes 4 parameters: the first 3 are the same as for Volunteer (name, address, phone number) and the 4th is the commission rate for the employee. The constructor should call the constructor of the parent class with the first 3 parameters then use the 4th to set the commission rate.

One additional method is needed: public void addSales (double totalSales) that adds the value to the instance variable representing total sales.

The pay method must call the pay method of the parent class to compute the pay from commission on sales. (See the pay method in the Executive class.) The total sales should be set back to 0.

The toString method needs to call the toString method of the parent class then add the total sales to that.

--Write a second class named FreeIntern using the same ideas as above, but be sure that it fits the scenario.

To test your classes, update Staff.java as follows:

Increase the size of the array to 10.

Add two interns to the staffList—make up your own names, addresses, and phone numbers. Have one of the employees earn a 10% commission and the other one earn a15% commission.

For the first additional employee you added, put the total sales $150; for the second, put the sales at $95.

Add two non-paid interns to the staffListThe files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 – 9.7 in the text. The program illustrates inheritance and polymorphism. In this exercise you will add two more employee types to the class hierarchy (see Figure 9.1 in the text). One of the new employee types will be an Intern, but earns a commission on sales. Hence the class, which we\'ll name CommissionIntern, will be derived from the Volunteer class. The second employee type will also be an Intern but is not paid, named FreeIntern.

--Write a class named CommissionIntern with the following features:

It extends the Volunteer class.

It will have an additional instance variable (in addition to those inherited) named commission_Rate for the employee (the commission rate will represent the percent (in decimal form) that the employee earns on sales (so .25 would mean the employee earns 25% commission on sales)).

You may want to create an additional instance variable to keep track of the total sales earned.

The constructor takes 4 parameters: the first 3 are the same as for Volunteer (name, address, phone number) and the 4th is the commission rate for the employee. The constructor should call the constructor of the parent class with the first 3 parameters then use the 4th to set the commission rate.

One additional method is needed: public void addSales (double totalSales) that adds the value to the instance variable representing total sales.

The pay method must call the pay method of the parent class to compute the pay from commission on sales. (See the pay method in the Executive class.) The total sales should be set back to 0.

The toString method needs to call the toString method of the parent class then add the total sales to that.

--Write a second class named FreeIntern using the same ideas as above, but be sure that it fits the scenario.

To test your classes, update Staff.java as follows:

Increase the size of the array to 10.

Add two interns to the staffList—make up your own names, addresses, and phone numbers. Have one of the employees earn a 10% commission and the other one earn a15% commission.

For the first additional employee you added, put the total sales $150; for the second, put the sales at $95.

Add two non-paid interns to the staffList

Solution

//CommissionIntern.java

class CommissionIntern extends Volunteer
{
   public float commissionRate;
   private double countSales = 0;
   Volunteer volunteer;
  
   public CommissionIntern(String name, String address, long phoneNumber, float commissionRate)
   {
       volunteer = new Volunteer(name, address, phoneNumber);
       this.commissionRate = commissionRate;
   }
  
   public void addSales(double totalSales)
   {
       countSales += totalSales;
   }
  
   public void pay()
   {
   volunteer.pay();
       countSales = 0;
   }
}

//FreeIntern.java

class FreeIntern extends Volunteer
{
   public float commissionRate;
   private double countSales = 0;
   Volunteer volunteer;
  
   public FreeIntern(String name, String address, long phoneNumber, float commissionRate)
   {
       volunteer = new Volunteer(name, address, phoneNumber);
       this.commissionRate = commissionRate;
   }
  
   public void addSales(double totalSales)
   {
       countSales += totalSales;
   }
  
   public void pay()
   {
   volunteer.pay();
       countSales = 0;
   }
}

//Staff.java

class Staff
{
   int[] staffArray = new int[10];
   ArrayList<Object> staffLists = new ArrayList();
  
   public Staff()
   {
   //paid
       CommissionIntern obj1 = new CommissionIntern(\"name1\", \"address1\", 9876543210, 0.10);
       CommissionIntern obj2 = new CommissionIntern(\"name2\", \"address2\", 9876543210, 0.15);
       staffLists.add(obj1);
       obj1.addSales(150);
       staffLists.add(obj2);
       obj2.addSales(95);
      
      
       //non-paid
       FreeIntern obj3 = new FreeIntern(\"name3\", \"address3\", 9876543210, 0);
       FreeIntern obj4 = new FreeIntern(\"name4\", \"address4\", 9876543210, 0);
       staffLists.add(obj3);
       staffLists.add(obj4);
   }
}

The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 – 9.7 in the text. The p
The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 – 9.7 in the text. The p
The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 – 9.7 in the text. The p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site