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

Create a class called Employee whose objects are records for an employee. This c

ID: 3642261 • Letter: C

Question

Create a class called Employee whose objects are records for an employee. This class will be a derived class of the class Person which is below. An employee record has an employee's name (inherited from the class Person), an annual salary represented as a single value of type double, a hire date the employee started work as a single value of type int and a identification number, which is a value of type String. Write a program to fully test your class definition.


public class Person
{
protected String name;

public Person( )
{
name = "No name yet";
}

public Person(String initialName)
{
name = initialName;
}

public void setName(String newName)
{
name = newName;
}

public String getName( )
{
return name;
}

public void writeOutput( )
{
System.out.println("Name: " + name);
}

public boolean hasSameName(Person otherPerson)
{
return this.name.equalsIgnoreCase(otherPerson.name);
}
}

Explanation / Answer

public class Employee extends Person {

       private double salary;

       private int date;

       private String ID;

       public Employee() {

              super();

              salary = 0;

              date = 0;

              ID = null;

       }

       public Employee(String name, double salary, int date, String ID) {

              super(name);

              this.salary = salary;

              this.date = date;

              this.ID = ID;

       }

       public double getSalary() {

              return salary;

       }

       public void setSalary(double salary) {

              this.salary = salary;

       }

       public int getDate() {

              return date;

       }

       public void setDate(int date) {

              this.date = date;

       }

       public String getID() {

              return ID;

       }

       public void setID(String iD) {

              ID = iD;

       }

       public String toString() {

              return "Employee " + ID + ": " + name + " started working on day " + date

                           + " and has a salary of $" + salary + "/year.";

       }

       public boolean isSameEmployee(Employee other)

       {

       return (name.equalsIgnoreCase(other.name) && this.ID.equalsIgnoreCase(other.getID())

                     && date == other.getDate() && salary == other.getSalary());

       }

}

public class EmployeeTest {

       public static void main(String[] args) {

              Employee>new Employee("Ted", 25000, 25, "353A");

              System.out.println(one.toString());

              Employee two = new Employee("Joe", 35000, 10, "24B");

              System.out.println(two.toString());

              System.out.println(two.getName() + " started working on day " + two.getDate()

                           + " and has a salary of $" + two.getSalary() + "/year. His employee number is "

                           + two.getID());

              if(one.hasSameName(two)) {

                     System.out.println("The two employees have the same name");

              }

              if(one.isSameEmployee(two)) {

                     System.out.println("The two employees are the same");

              }

              two.setDate(one.getDate());

              two.setID(one.getID());

              two.setName(one.getName());

              two.setSalary(one.getSalary());

              if(one.isSameEmployee(two)) {

                     System.out.println("The two employees are now the same");

              }

       }

}

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