In Java Modify the original Firm Java code so that all emplo

In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver class to demonstrate this capability. This is an example of the output:

run:

Name: Sam

Address: 123 Main Line

Phone: 555-0469

Social Security Number:123-45-6789

Paid: 2923.07

Vacation days available: 26

-----------------------------------

Name: Carla

Address: 456 Off Line

Phone: 555-0101

Social Security Number: 987-65-4321

Paid: 1246.15

Vacation days available: 14

-----------------------------------

Name: Woody

Address: 789 Off Rocker

Phone: 555-0000

Social Security Number: 010-20-3040

Paid: 1169.23

Vacation days available: 14

-----------------------------------

Name: Diane

Address: 678 Fifth Ave.

Phone: 555-0690

Social Security Number: 958-47-3625

Current hours: 40

Paid: 422.0

Vacation days available: 7

-----------------------------------

Name: Norm

Address: 987 Suds Blvd.

Phone: 555-8374

Thanks!

Vacation days available: 0

-----------------------------------

Name: Cliff

Address: 321 Duds Lane

Phone: 555-7282

Thanks!

Vacation days available: 0

-----------------------------------

BUILD SUCCESSFUL (total time: 0 second

CODE:

package firm;

public class Firm
{
   //-----------------------------------------------------------------
   // Creates a staff of employees for a firm and pays them.
   //-----------------------------------------------------------------
   public static void main(String[] args)
   {
      Staff personnel = new Staff();

      personnel.payday();
   }
}


NEW FILE


package firm;

public class Staff
{
    private StaffMember[] staffList;
   //-----------------------------------------------------------------
   // Constructor: Sets up the list of staff members.
   //-----------------------------------------------------------------
   public Staff()
   {
      staffList = new StaffMember[6];

      staffList[0] = new Executive(\"Sam\", \"123 Main Line\",
         \"555-0469\", \"123-45-6789\", 2423.07);

      staffList[1] = new Employee(\"Carla\", \"456 Off Line\",
         \"555-0101\", \"987-65-4321\", 1246.15);
      staffList[2] = new Employee(\"Woody\", \"789 Off Rocker\",
         \"555-0000\", \"010-20-3040\", 1169.23);

      staffList[3] = new Hourly(\"Diane\", \"678 Fifth Ave.\",
         \"555-0690\", \"958-47-3625\", 10.55);

      staffList[4] = new Volunteer(\"Norm\", \"987 Suds Blvd.\",
         \"555-8374\");
      staffList[5] = new Volunteer(\"Cliff\", \"321 Duds Lane\",
         \"555-7282\");

      ((Executive)staffList[0]).awardBonus(500.00);

      ((Hourly)staffList[3]).addHours(40);
   }

   //-----------------------------------------------------------------
   // Pays all staff members.
   //-----------------------------------------------------------------
   public void payday ()
   {
      double amount;

      for (int count=0; count < staffList.length; count++)
      {
         System.out.println(staffList[count]);

         amount = staffList[count].pay(); // polymorphic

         if (amount == 0.0)
            System.out.println(\"Thanks!\");
         else
            System.out.println(\"Paid: \" + amount);

         System.out.println(\"-----------------------------------\");
      }
   }
}


NEW FILE


package firm;

abstract public class StaffMember
{
   protected String name;
   protected String address;
   protected String phone;

   //-----------------------------------------------------------------
   // Constructor: Sets up this staff member using the specified
   // information.
   //-----------------------------------------------------------------
   public StaffMember(String eName, String eAddress, String ePhone)
   {
      name = eName;
      address = eAddress;
      phone = ePhone;
   }

   //-----------------------------------------------------------------
   // Returns a string including the basic employee information.
   //-----------------------------------------------------------------
   public String toString()
   {
      String result = \"Name: \" + name + \"\ \";

      result += \"Address: \" + address + \"\ \";
      result += \"Phone: \" + phone;

      return result;
   }

   //-----------------------------------------------------------------
   // Derived classes must define the pay method for each type of
   // employee.
   //-----------------------------------------------------------------
   public abstract double pay();
}


NEW FILE


package firm;

public class Volunteer extends StaffMember
{
   //-----------------------------------------------------------------
   // Constructor: Sets up this volunteer using the specified
   // information.
   //-----------------------------------------------------------------
   public Volunteer(String eName, String eAddress, String ePhone)
   {
      super(eName, eAddress, ePhone);
   }

   //-----------------------------------------------------------------
   // Returns a zero pay value for this volunteer.
   //-----------------------------------------------------------------
   public double pay()
   {
      return 0.0;
   }
}

NEW FILE


package firm;

public class Employee extends StaffMember
{
   protected String socialSecurityNumber;
   protected double payRate;

   //-----------------------------------------------------------------
   // Constructor: Sets up this employee with the specified
   // information.
   //-----------------------------------------------------------------
   public Employee(String eName, String eAddress, String ePhone,
                   String socSecNumber, double rate)
   {
      super(eName, eAddress, ePhone);

      socialSecurityNumber = socSecNumber;
      payRate = rate;
   }

   //-----------------------------------------------------------------
   // Returns information about an employee as a string.
   //-----------------------------------------------------------------
   public String toString()
   {
      String result = super.toString();

      result += \"\ Social Security Number: \" + socialSecurityNumber;

      return result;
   }

   //-----------------------------------------------------------------
   // Returns the pay rate for this employee.
   //-----------------------------------------------------------------
   public double pay()
   {
      return payRate;
   }
}


NEW FILE


package firm;

public class Executive extends Employee
{
   private double bonus;

   //-----------------------------------------------------------------
   // Constructor: Sets up this executive with the specified
   // information.
   //-----------------------------------------------------------------
   public Executive(String eName, String eAddress, String ePhone,
                    String socSecNumber, double rate)
   {
      super(eName, eAddress, ePhone, socSecNumber, rate);

      bonus = 0; // bonus has yet to be awarded
   }

   //-----------------------------------------------------------------
   // Awards the specified bonus to this executive.
   //-----------------------------------------------------------------
   public void awardBonus(double execBonus)
   {
      bonus = execBonus;
   }

   //-----------------------------------------------------------------
   // Computes and returns the pay for an executive, which is the
   // regular employee payment plus a one-time bonus.
   //-----------------------------------------------------------------
   public double pay()
   {
      double payment = super.pay() + bonus;

      bonus = 0;

      return payment;
   }
}


NEW FILE


package firm;


public class Hourly extends Employee
{
   private int hoursWorked;

   //-----------------------------------------------------------------
   // Constructor: Sets up this hourly employee using the specified
   // information.
   //-----------------------------------------------------------------
   public Hourly(String eName, String eAddress, String ePhone,
                 String socSecNumber, double rate)
   {
      super(eName, eAddress, ePhone, socSecNumber, rate);

      hoursWorked = 0;
   }

   //-----------------------------------------------------------------
   // Adds the specified number of hours to this employee\'s
   // accumulated hours.
   //-----------------------------------------------------------------
   public void addHours(int moreHours)
   {
      hoursWorked += moreHours;
   }

   //-----------------------------------------------------------------
   // Computes and returns the pay for this hourly employee.
   //-----------------------------------------------------------------
   public double pay()
   {
      double payment = payRate * hoursWorked;

      hoursWorked = 0;

      return payment;
   }

   //-----------------------------------------------------------------
   // Returns information about this hourly employee as a string.
   //-----------------------------------------------------------------
   public String toString()
   {
      String result = super.toString();

      result += \"\ Current hours: \" + hoursWorked;

      return result;
   }
}

Solution

Firm.Java Class:

----------------------------------------------------------------------------------------------------------------------------------------------------------

public class Firm
{
//-----------------------------------------------------------------
// Creates a staff of employees for a firm and pays them.
//-----------------------------------------------------------------
public static void main(String[] args)
{
   Staff personnel = new Staff();

   personnel.payday();
  
}
}

------------------------------------------------------------------------------------------------------------------------------------------------

Staff.Java:

------------------------------------------------------------------------------------------------------------------------------------------------

public class Staff
{
private StaffMember[] staffList;

//-----------------------------------------------------------------
// Constructor: Sets up the list of staff members.
//-----------------------------------------------------------------
public Staff()
{
staffList = new StaffMember[6];

staffList[0] = new Executive(\"Sam\", \"123 Main Line\",
     \"555-0469\", \"123-45-6789\", 2423.07, 12);

staffList[1] = new Employee(\"Carla\", \"456 Off Line\",
     \"555-0101\", \"987-65-4321\", 1246.15, 14);
staffList[2] = new Employee(\"Woody\", \"789 Off Rocker\",
     \"555-0000\", \"010-20-3040\", 1169.23, 13);

staffList[3] = new Hourly(\"Diane\", \"678 Fifth Ave.\",
     \"555-0690\", \"958-47-3625\", 10.55, 10);

staffList[4] = new Volunteer(\"Norm\", \"987 Suds Blvd.\",
     \"555-8374\");
staffList[5] = new Volunteer(\"Cliff\", \"321 Duds Lane\",
     \"555-7282\");

((Executive)staffList[0]).awardBonus(500.00);

((Hourly)staffList[3]).addHours(40);
}

//-----------------------------------------------------------------
// Pays all staff members.
//-----------------------------------------------------------------
public void payday ()
{
double amount;

for (int count=0; count < staffList.length; count++)
{
     System.out.println(staffList[count]);

     amount = staffList[count].pay(); // polymorphic

     if (amount == 0.0)
        System.out.println(\"Thanks!\");
     else
        System.out.println(\"Paid: \" + amount);

     System.out.println(\"-----------------------------------\");
}
}


}

------------------------------------------------------------------------------------------------------------------------------------------------

StaffMember.java:

------------------------------------------------------------------------------------------------------------------------------------------------

abstract public class StaffMember
{
protected String name;
protected String address;
protected String phone;

//-----------------------------------------------------------------
// Constructor: Sets up this staff member using the specified
// information.
//-----------------------------------------------------------------
public StaffMember(String eName, String eAddress, String ePhone)
{
name = eName;
address = eAddress;
phone = ePhone;
}

//-----------------------------------------------------------------
// Returns a string including the basic employee information.
//-----------------------------------------------------------------
public String toString()
{
String result = \"Name: \" + name + \"\ \";

result += \"Address: \" + address + \"\ \";
result += \"Phone: \" + phone;

return result;
}

//-----------------------------------------------------------------
// Derived classes must define the pay method for each type of
// employee.
//-----------------------------------------------------------------
public abstract double pay();

public abstract int vacation();
}

------------------------------------------------------------------------------------------------------------------------------------------------

Volunteer.java:

------------------------------------------------------------------------------------------------------------------------------------------------

public class Volunteer extends StaffMember
{
//-----------------------------------------------------------------
// Constructor: Sets up this volunteer using the specified
// information.
//-----------------------------------------------------------------
public Volunteer(String eName, String eAddress, String ePhone)
{
super(eName, eAddress, ePhone);
}

//-----------------------------------------------------------------
// Returns a zero pay value for this volunteer.
//-----------------------------------------------------------------
public double pay()
{
return 0.0;
}

@Override
public int vacation() {

   return 1;
}
public String toString()
{
String result = super.toString();

result += \"\ Vacastion Days Available: \" + vacation();

return result;
}
}

------------------------------------------------------------------------------------------------------------------------------------------------

Employee.java:

------------------------------------------------------------------------------------------------------------------------------------------------

public class Employee extends StaffMember
{
protected String socialSecurityNumber;
protected double payRate;
protected int vacation;

//-----------------------------------------------------------------
// Constructor: Sets up this employee with the specified
// information.
//-----------------------------------------------------------------
public Employee(String eName, String eAddress, String ePhone,
               String socSecNumber, double rate, int vacation)
{
super(eName, eAddress, ePhone);

socialSecurityNumber = socSecNumber;
payRate = rate;
this.vacation = vacation;
}

//-----------------------------------------------------------------
// Returns information about an employee as a string.
//-----------------------------------------------------------------
public String toString()
{
String result = super.toString();

result += \"\ Social Security Number: \" + socialSecurityNumber;
result += \"\ Number of Vacstion Days: \" + vacation;

return result;
}

//-----------------------------------------------------------------
// Returns the pay rate for this employee.
//-----------------------------------------------------------------
public double pay()
{
return payRate;
}

@Override
public int vacation() {
  
   return vacation;
}
}

------------------------------------------------------------------------------------------------------------------------------------------------

Executive.java:

------------------------------------------------------------------------------------------------------------------------------------------------

public class Executive extends Employee
{
   private double bonus;
  
//-----------------------------------------------------------------
// Constructor: Sets up this executive with the specified
// information.
//-----------------------------------------------------------------
public Executive(String eName, String eAddress, String ePhone,
                String socSecNumber, double rate ,int vacation)
{
super(eName, eAddress, ePhone, socSecNumber, rate, vacation);

bonus = 0; // bonus has yet to be awarded
}

//-----------------------------------------------------------------
// Awards the specified bonus to this executive.
//-----------------------------------------------------------------
public void awardBonus(double execBonus)
{
bonus = execBonus;
}

//-----------------------------------------------------------------
// Computes and returns the pay for an executive, which is the
// regular employee payment plus a one-time bonus.
//-----------------------------------------------------------------
public double pay()
{
double payment = super.pay() + bonus;

bonus = 0;

return payment;
}
}

------------------------------------------------------------------------------------------------------------------------------------------------

Hourly.java:

------------------------------------------------------------------------------------------------------------------------------------------------

public class Hourly extends Employee
{
private int hoursWorked;
protected int vacation;
//-----------------------------------------------------------------
// Constructor: Sets up this hourly employee using the specified
// information.
//-----------------------------------------------------------------
public Hourly(String eName, String eAddress, String ePhone,
             String socSecNumber, double rate, int vacation)
{
super(eName, eAddress, ePhone, socSecNumber, rate, vacation);

hoursWorked = 0;
}

//-----------------------------------------------------------------
// Adds the specified number of hours to this employee\'s
// accumulated hours.
//-----------------------------------------------------------------
public void addHours(int moreHours)
{
hoursWorked += moreHours;
}

//-----------------------------------------------------------------
// Computes and returns the pay for this hourly employee.
//-----------------------------------------------------------------
public double pay()
{
double payment = payRate * hoursWorked;

hoursWorked = 0;

return payment;
}

//-----------------------------------------------------------------
// Returns information about this hourly employee as a string.
//-----------------------------------------------------------------
public String toString()
{
String result = super.toString();

result += \"\ Current hours: \" + hoursWorked;

return result;
}
}

------------------------------------------------------------------------------------------------------------------------------------------------

OUTPUT:

Name: Sam

Address: 123 Main Line

Phone: 555-0469

Social Security Number:123-45-6789

Paid: 2923.07

Vacation days available: 26

-----------------------------------

Name: Carla

Address: 456 Off Line

Phone: 555-0101

Social Security Number: 987-65-4321

Paid: 1246.15

Vacation days available: 14

-----------------------------------

Name: Woody

Address: 789 Off Rocker

Phone: 555-0000

Social Security Number: 010-20-3040

Paid: 1169.23

Vacation days available: 14

-----------------------------------

Name: Diane

Address: 678 Fifth Ave.

Phone: 555-0690

Social Security Number: 958-47-3625

Current hours: 40

Paid: 422.0

Vacation days available: 7

-----------------------------------

Name: Norm

Address: 987 Suds Blvd.

Phone: 555-8374

Thanks!

Vacation days available: 0

-----------------------------------

Name: Cliff

Address: 321 Duds Lane

Phone: 555-7282

Thanks!

Vacation days available: 0

In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c
In Java, Modify the original Firm Java code so that all employees can be given different vacation options depending on their classification. Modify the driver c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site