Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Java to create the following classes below. Part 1: Create an interface ca

ID: 3859040 • Letter: U

Question

Using Java to create the following classes below.

Part 1:

Create an interface called Employable.

It has the following methods:

public String getDressCode()
public boolean isPaidSalary()
public boolean postSecondaryEducationRequired()
public String getWorkVerb()
default public boolean getsPaid(){
   return true;
}

Create an abstract class Employee which defines one abstract method:
public double getOverTimePayRate(). It also has a String name instance variable. It also implements Employable.

Create the following classes which descend from class Employee; their respective return values for the Employable-interface methods are listed here.

HockeyPlayer (“jersey”, true, false, “play”);               OVERTIME_PAY_RATE: 0.0
Professor (“fancy”, true, true, “teach”);                      OVERTIME_PAY_RATE: 2.0
Parent(“anything”, false, false, “care”);                      OVERTIME_PAY_RATE: -2.0
GasStationAttendant(“uniform”, false, false, “pump”); OVERTIME_PAY_RATE: 1.5

Define the following instance variables for these classes:
HockeyPlayer:                     int numberOfGoals
Professor:                             String teachingMajor
Parent:                                  int numberOfHoursSpentPerWeekWithKids
GasStationAttendant:       double numberOfDollarsStolenPerDay

Create a class called Employees which has an ArrayList of 20 Employee references. The constructor adds five of each type of Employee above, in this order:

HockeyPlayer                      Wayne Gretzky       scored 894 goals
HockeyPlayer                      Who Ever                 scored 0 goals
HockeyPlayer                      Brent Gretzky          scored 1 goal
HockeyPlayer                      Pavel Bure                scored 437 goals
HockeyPlayer                      Jason Harrison        scored 0 goals

Professor                              Albert Einstein         teaches Physics
Professor                              Jason Harrison        teaches Computer Systems
Professor                              Richard Feynman   teaches Physics
Professor                              BCIT Instructor        teaches Computer Systems
Professor                              Kurt Godel                teaches Logic

Parent                                   Tiger Woods            spends 1 hour/week with kids
Parent                                   Super Mom              spends 168 hours/week with kids
Parent                                   Lazy Larry                 spends 20 hours/week with kids
Parent                                   Ex Hausted               spends 168 hours/week with kids
Parent                                   Super Dad                spends 167 hours/week with kids

Parent must also @Override getsPaid() to return false.

GasStationAttendant        Joe Smith                  steals 10 dollars a day
GasStationAttendant        Tony Baloney           steals 100 dollars a day
GasStationAttendant        Benjamin Franklin steals 100 dollars a day
GasStationAttendant        Mary Fairy                steals 101 dollars a day
GasStationAttendant        Bee See                     steals 1 dollar a day

Part 2:

The Employee subclasses must override the Object class’s equals method, and also must implement the Comparable interface.

To implement the Comparable interface, the following relationships must be defined:

HockeyPlayers with the most goals are considered “highest”.

Professors who teach Computer Science are considered “highest”; others are equal.

Parents who spend the most hours/week with their kids are considered “highest”.

GasStationAttendants who steal the most per week are considered “highest”.

NOTE: Create separate ArrayLists for each child class!

Use Collections.sort(yourArrayList) to sort each of your four Employees collections. Print them out before and after sorting. The Collections.sort() method automatically uses the compareTo() method you defined.

To override the equals method, each of the four Employee subclasses must implement the following method:

@Override public boolean equals(Object that)

Which returns the following values:

- true, if this == that
- false, if that == null
- false, if that is not an instanceof the same class (.getClass() != .getClass())
- true for HockeyPlayers if and only if they score the same number of goals
- true for Professors if and only if they teach the same subject
- true for Parents if and only if they parent the same number of hours
- true for GasStationAttendants if and only if they steal the same amount.

The Employees class must contain a method that displays all objects that are equal to one another.

Whenever you override the equals() method you must also override the hashCode() method. Let eclipse do it for you, or do it as follows:

public int hashCode () {

return 0;
}

Please follow the instructions above for a good rate

Explanation / Answer

Main.java
-----------------------------------
public class Main {

    public static void main(String[] args)
    {
        run();
    }

    private static void run()
    {
        System.out.println("Start ...");
    }
}
------------------------------------------------------------
Employee.java
-----------------------------------
public abstract class Employee implements Employable
{
    private String name;

    public Employee(String name)
    {
        setName(name);
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public abstract double getOverTimePayRate();
}
------------------------------------------------------------
Employees.java
-----------------------------------
import java.util.ArrayList;

public class Employees
{
    private ArrayList<Employee> emp;

    public Employees()
    {
        emp = new ArrayList<>();

        emp.add(new HockeyPlayer("Wayne Gretzky", 894));
        emp.add(new HockeyPlayer("Who Ever", 0));
        emp.add(new HockeyPlayer("Brent Gretzky", 1));
        emp.add(new HockeyPlayer("Pavel Bure",437));
        emp.add(new HockeyPlayer("Jason Harrison",0));

        emp.add(new Professor("Albert Einstein","Physics"));
        emp.add(new Professor("Jason Harrison",   "Computer Systems"));
        emp.add(new Professor("Richard Feynman","Physics"));
        emp.add(new Professor("BCIT Instructor","Computer Systems"));
        emp.add(new Professor("Kurt Godel","Logic"));

        emp.add(new Parents("Tiger Woods",1));
        emp.add(new Parents("Super Mom",168 ));
        emp.add(new Parents("Lazy Larry", 20));
        emp.add(new Parents("Ex Hausted",168));
        emp.add(new Parents("Super Dad",167));

        emp.add(new GasStationAttendant("Joe Smith", 10));
        emp.add(new GasStationAttendant("Tony Baloney", 100));
        emp.add(new GasStationAttendant("Benjamin Franklin", 100));
        emp.add(new GasStationAttendant("Mary Fairy", 101));
        emp.add(new GasStationAttendant("Bee See", 1));
    }
}
------------------------------------------------------------
Employable.java
-----------------------------------
public interface Employable {

        public String getDressCode();
        public boolean isPaidSalary();
        public boolean postSecondaryEducationRequired();
        public String getWorkVerb();
}


------------------------------------------------------------
GasStationAttendant.java
-----------------------------------
public class GasStationAttendant extends Employee implements Comparable<GasStationAttendant>
{
    private double numberOfDollarsStolenPerDay;

    public GasStationAttendant(String name, double numberOfDollarsStolenPerDay)
    {
        super(name);
        setNumberOfDollarsStolenPerDay(numberOfDollarsStolenPerDay);
    }

    public double getNumberOfDollarsStolenPerDay()
    {
        return numberOfDollarsStolenPerDay;
    }

    public void setNumberOfDollarsStolenPerDay(double numberOfDollarsStolenPerDay)
    {
        this.numberOfDollarsStolenPerDay = numberOfDollarsStolenPerDay;
    }

    @Override
    public String getDressCode()
    {
        return null;
    }

    @Override
    public boolean isPaidSalary()
    {
        return false;
    }

    @Override
    public boolean postSecondaryEducationRequired()
    {
        return false;
    }

    @Override
    public String getWorkVerb()
    {
        return null;
    }

    @Override
    public double getOverTimePayRate()
    {
        return 1.5;
    }

    @Override
    public int compareTo(GasStationAttendant gsa)
    {
        if(numberOfDollarsStolenPerDay==gsa.numberOfDollarsStolenPerDay)
            return 0;
        else if(numberOfDollarsStolenPerDay > gsa.numberOfDollarsStolenPerDay)
            return 1;
        else
            return -1;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        long temp;
        temp = Double.doubleToLongBits(numberOfDollarsStolenPerDay);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;

        if (obj == null)
            return false;

        if (!(obj instanceof GasStationAttendant))
            return false;

        GasStationAttendant other = (GasStationAttendant) obj;

        if (Double.doubleToLongBits(numberOfDollarsStolenPerDay) != Double
                .doubleToLongBits(other.numberOfDollarsStolenPerDay))
            return false;

        return true;
    }
}
------------------------------------------------------------
HockeyPlayer.java
-----------------------------------
public class HockeyPlayer extends Employee implements Comparable<HockeyPlayer>
{
    private int numberOfGoals;

    public HockeyPlayer(String name, int numberOfGoals)
    {
        super(name);
        setNumberOfGoals(numberOfGoals);
    }

    public int getNumberOfGoals()
    {
        return numberOfGoals;
    }

    public void setNumberOfGoals(int numberOfGoals)
    {
        this.numberOfGoals = numberOfGoals;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + numberOfGoals;
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;

        if (obj == null)
            return false;

        if (!(obj instanceof HockeyPlayer))
            return false;

        HockeyPlayer other = (HockeyPlayer) obj;

        if (numberOfGoals != other.numberOfGoals)
            return false;

        return true;
    }

    @Override
    public double getOverTimePayRate()
    {
        return 0.0;
    }

    @Override
    public String getDressCode() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isPaidSalary() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean postSecondaryEducationRequired() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public String getWorkVerb() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int compareTo(HockeyPlayer hp)
    {
        if(numberOfGoals==hp.numberOfGoals)
            return 0;
        else if(numberOfGoals>hp.numberOfGoals)
            return 1;
        else
            return -1;
    }
}
------------------------------------------------------------
Parents.java
-----------------------------------
public class Parents extends Employee implements Comparable<Parents>
{
    private int numberOfHoursSpentPerWeekWithKids;

    public Parents(String name, int numberOfHoursSpentPerWeekWithKids)
    {
        super(name);
        setNumberOfHoursSpentPerWeekWithKids(numberOfHoursSpentPerWeekWithKids);
    }

    public int getNumberOfHoursSpentPerWeekWithKids()
    {
        return numberOfHoursSpentPerWeekWithKids;
    }

    public void setNumberOfHoursSpentPerWeekWithKids(int numberOfHoursSpentPerWeekWithKids)
    {
        this.numberOfHoursSpentPerWeekWithKids = numberOfHoursSpentPerWeekWithKids;
    }

    @Override
    public String getDressCode()
    {
        return null;
    }

    @Override
    public boolean isPaidSalary()
    {
        return false;
    }

    @Override
    public boolean postSecondaryEducationRequired()
    {
        return false;
    }

    @Override
    public String getWorkVerb()
    {
        return null;
    }

    @Override
    public double getOverTimePayRate()
    {
        return -2.0;
    }

    @Override
    public int compareTo(Parents parents)
    {
        if(numberOfHoursSpentPerWeekWithKids== parents.numberOfHoursSpentPerWeekWithKids)
            return 0;
        else if(numberOfHoursSpentPerWeekWithKids > parents.numberOfHoursSpentPerWeekWithKids)
            return 1;
        else
            return -1;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + numberOfHoursSpentPerWeekWithKids;
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;

        if (obj == null)
            return false;

        if (!(obj instanceof Parents))
            return false;

        Parents other = (Parents) obj;

        if (numberOfHoursSpentPerWeekWithKids != other.numberOfHoursSpentPerWeekWithKids)
            return false;

        return true;
    }
}
------------------------------------------------------------
Professor.java
-----------------------------------

public class Professor extends Employee implements Comparable<Professor>
{
    private String teachingMajor;

    public Professor(String name, String teachingMajor)
    {
        super(name);
        this.teachingMajor = teachingMajor;
    }

    public String getTeachingMajor()
    {
        return teachingMajor;
    }

    public void setTeachingMajor(String teachingMajor)
    {
        this.teachingMajor = teachingMajor;
    }

    @Override
    public String getDressCode()
    {
        return null;
    }

    @Override
    public boolean isPaidSalary()
    {
        return false;
    }

    @Override
    public boolean postSecondaryEducationRequired()
    {
        return false;
    }

    @Override
    public String getWorkVerb()
    {
        return null;
    }

    @Override
    public double getOverTimePayRate()
    {
        return 2.0;
    }

    @Override
    public int compareTo(Professor prof)
    {
        if(teachingMajor.equalsIgnoreCase("Computer Science"))
            return 1;
        else
            return 0;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((teachingMajor == null) ? 0 : teachingMajor.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;

        if (obj == null)
            return false;

        if (!(obj instanceof Professor))
            return false;

        Professor other = (Professor) obj;

        if (teachingMajor == null)
        {
            if (other.teachingMajor != null)
                return false;
        } else if (!teachingMajor.equals(other.teachingMajor))
            return false;

        return true;
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote