Create a new Employee Class
Build a new Employee class("Employee.java"). This class will be a sub-class of Person. So it will inherit all the properties of Person(FirstName, LastName, Address and Email). Also add 2 new properties, an employee id number and a salary. Create this class, make sure to add 2 constructors(one that takes no args and 1 that takes all props from both the Person class and the Employee class) and a display() method that prints out all the props from both the Person class and the Employee class. Then use main to test out this class.
Main Code -->
Employee e1;
e1 = new Employee(2323, "Bill", "Clinton", "Marietta", "bc@msn.com", 43000.00);
e1.display();
What I have tried:
Person class code:
public class Person {
private String FirstName;
private String LastName;
private String Address;
private String Email;
Person(String FirstName,String LastName,String Address,String Email) {
this.FirstName = FirstName;
this.LastName = LastName;
this.Address = Address;
this.Email = Email;
}
Person() {
this.FirstName = "";
this.LastName = "";
this.Address = "";
this.Email = "";
}
public void setFirstName(String fn) {
this.FirstName = fn;
}
public void setLastName(String ln) {
this.LastName = ln;
}
public void setAddress(String a) {
this.Address = a;
}
public void setEmail(String e) {
this.Email = e;
}
public String getFirstName() {
return this.FirstName;
}
public String getLastName() {
return this.LastName;
}
public String getAddress() {
return this.Address;
}
public String getEmail() {
return this.Email;
}
public void display() {
System.out.println("First Name : "+this.FirstName);
System.out.println("Last Name : "+this.LastName);
System.out.println("Address : "+this.Address);
System.out.println("Email : "+this.Email);
}
public String toString() {
return "FirstName: "+getFirstName() + "\nLastName: "+getLastName() + "\n" +this.Address.toString()
+"\nEmail: "+getEmail();
}
public static void main(String args []) {
Person p1;
p1 = new Person("Rodney","Duncan","70 Bowman St. South Windsor, CT 06074","rduncan@gmail.com");
p1.display();
}
}
Employee class code so far:
public class Employee extends Person {
private int employeeId;
private int salary;
public Employee() {
super();
this.employeeId = 0;
this.salary = "";
}