Create a class called Employee
whose objects are records for an employee. This class will be a derived class of the class Person
which you will have to create. 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 year the employee started work as a single value of type int
and a social security number, which is a value of type String
.
Write a class containing a main()
method to fully test your class definition.
Person
class requirements:
- One
private
attribute of typeString
that stores the name of the person object, with getter and setter. - Default constructor that creates a person object with an empty string (
""
) as the name attribute. - A constructor that accepts a string to be assigned as the name of the object.
- Override the
toString
method so it returns a string representation of thePerson
object, which should be the name attribute. - Implement the
public boolean equals(Object otherPerson)
method so it returns if the name ofthis
object is the same as the name of theotherPerson
object or not.
public class Person {}
Employee
class requirements:
- One
private double
attribute to hold the value for the annual salary of the employee, with a getter methodgetSalary()
. - A
private int
attribute to store the year which the employee started working with a getter methodgetYear()
. - A
private String
attribute to stode the social security number of the employee. - A constructor that accepts four parameters in this order: a
String
for the name, adouble
for the annual salary, anint
for the starting year, and anotherString
for the social security number. - Override the
equals()
method so that it compares the social security number of the objects, instead of the name attribute.
public class Employee {}
Hints:
- To compare two
String
objects (s1
ands2
), you can use theequals
method from theString
class:s1.equals(s2)
. - Use the
equals()
method that you implement for this assignment the same way you would use it to compareString
objects. - You can downcast from a parent type to a child type to have access to the child's methods (usefull for the equals method).
- Accept the assignment when posted on Moodle
- Clone the assignment repository
- Solve the assignment
- Submit (
commit
andpush
) the assignment- Resubmit if necessary or contact the instructor for questions.