Define a class named Employee whose objects are records for employees. Derive th
ID: 3606687 • Letter: D
Question
Define a 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.
Describe the problem including input and output and Provide UML class diagram tables with three rows, use appropriate shapes, lines to indicate class relationship
Explanation / Answer
Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.
_________________
Person.java
public class Person {
// Declaring instance variables
private String name;
// Parameterized constructor
public Person(String name) {
super();
this.name = name;
}
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// toString method is used to display the contents of an object inside it
@Override
public String toString() {
return " Name=" + name;
}
}
________________
Address.java
public class Address {
//Declaring instance variables
private String steet;
private String city;
private int zipcode;
private String state;
private boolean isCurrentAddress;
//Parameterized constructor
public Address(String steet, String city, int zipcode, String state,
boolean isCurrentAddress) {
super();
this.steet = steet;
this.city = city;
this.zipcode = zipcode;
this.state = state;
this.isCurrentAddress = isCurrentAddress;
}
//getters and setters
public String getSteet() {
return steet;
}
public void setSteet(String steet) {
this.steet = steet;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getZipcode() {
return zipcode;
}
public void setZipcode(int zipcode) {
this.zipcode = zipcode;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public boolean isCurrentAddress() {
return isCurrentAddress;
}
public void setCurrentAddress(boolean isCurrentAddress) {
this.isCurrentAddress = isCurrentAddress;
}
//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return " Steet=" + steet + ", city=" + city + ", zipcode=" + zipcode + ", state=" + state + ", isCurrentAddress=" + isCurrentAddress;
}
}
_________________
Employee.java
public class Employee extends Person {
//Declaring instance variables
private double annualSalary;
private Address address;
private int yearHired;
private String identificationNo;
//Parameterized constructor
public Employee(String name, double annualSalary, Address address,
int yearHired, String identificationNo) {
super(name);
this.annualSalary = annualSalary;
this.address = address;
this.yearHired = yearHired;
this.identificationNo = identificationNo;
}
//getters and setters
public double getAnnualSalary() {
return annualSalary;
}
public void setAnnualSalary(double annualSalary) {
this.annualSalary = annualSalary;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public int getYearHired() {
return yearHired;
}
public void setYearHired(int yearHired) {
this.yearHired = yearHired;
}
public String getIdentificationNo() {
return identificationNo;
}
public void setIdentificationNo(String identificationNo) {
this.identificationNo = identificationNo;
}
//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return super.toString() + " Annual Salary=" + annualSalary + ", " + address + ", yearHired=" + yearHired + ", identificationNo=" + identificationNo;
}
}
________________
Test.java
public class Test {
public static void main(String[] args) {
//Creating an Instance of Address class object
Address address = new Address("Bandra", "Mumbai", 56785, "Maharastra", true);
//Creating an Instance of Employee class object
Employee employee = new Employee("Sachin Tendulkar", 50000, address, 2010, "1111AS");
//Displaying the Employee class info
System.out.println(employee);
}
}
____________________
Output:
Name=Sachin Tendulkar Annual Salary=50000.0, Steet=Bandra, city=Mumbai, zipcode=56785, state=Maharastra, isCurrentAddress=true, yearHired=2010, identificationNo=1111AS
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.