Define a java class named Employee whose objects are records for employees. Deri
ID: 3600508 • Letter: D
Question
Define a java class named Employee whose objects are records for employees.
Derive this class from the class Person class included in this folder. An employee has an aggregated address class. Address contains Street Name, city, zip code (numeric), State, and isCurrentAddress (Boolean) fields.
An employee record inherits an employee’s name from the class Person. In addition, an employee record contains an annual salary represented as a single value of type double, a hire date that gives the year hired as a single value of type int, and an identification number that is a value of type String.
Give your class a reasonable complement of constructors, accessor methods, and mutator methods, as well as an equals method. There are Fulltime and Part time employees, you will be applying the concepts of polymorphism to create these two types of employees. Check if the employee is full time or part time. Write a program to fully test your class definition and all your methods.
write detailed pseudocode describing the major steps for solving the problem and coding.
Explanation / Answer
class Person
{
private String name;
public Person(String name)
{
this.name = name;
}
public String toString()
{
return " "+name;
}
}
class Address
{
private String streetName, city;
private int zipCode;
private String state;
private boolean isCurrentAddress;
public Address(String streetName,String city,int zipCode,String state,boolean isCurrentAddress)
{
this.streetName = streetName;
this.city = city;
this.zipCode = zipCode;
this.state = state;
this.isCurrentAddress = isCurrentAddress;
}
public String toString() //override toString method
{
return " Address : "+streetName +" "+ city +" "+ zipCode+ " "+state + " currently residing : "+isCurrentAddress;
}
}
class Employee extends Person
{
private double annualSalary;
private int hiredate;
private String idNumber;
private Address address; //aggregated Address class
public Employee(String name,double annualSalary,int hiredate,String idNumber,Address address)
{
super(name);//sending arguments to base class constructor
this.annualSalary = annualSalary;
this.hiredate = hiredate;
this.idNumber = idNumber;
this.address = address;
}
public String toString()
{
super.toString();
return "Employee : annual Salary : "+annualSalary +" hire date : "+hiredate +" id number : "+idNumber + address.toString();
}
}
class FulltimeEmployee extends Employee
{
private String empType;
public FulltimeEmployee(String name,double annualSalary,int hiredate,String idNumber,Address address)
{
super(name,annualSalary,hiredate,idNumber,address);
this.empType = "Full time";
}
public String toString()
{
return " Full time "+super.toString();
}
}
class ParttimeEmployee extends Employee
{
private String empType;
public ParttimeEmployee(String name,double annualSalary,int hiredate,String idNumber,Address address)
{
super(name,annualSalary,hiredate,idNumber,address);
this.empType = "Part time";
}
public String toString()
{
return " Part time "+super.toString();
}
}
class Test
{
public static void main (String[] args)
{
Address address = new Address("1224,DownStreet","Hillside",1788,"NJ",true);
ParttimeEmployee pe = new ParttimeEmployee("John Smith",5677.89,6,"E1007",address);
System.out.println(pe);
}
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.