Question: Java Inheritance: Build a new Teller class(Teller.java). This class will be a sub-class of Employee. The Teller class should have all the same properties as

Java Inheritance:

Build a new Teller class(Teller.java). This class will be a sub-class of Employee. The Teller class should have all the same properties as an Employee as well as two new properties: hoursWorked and shift. HoursWorked is the total hours that this teller worked this week, and shift is either day or evening shift. Make sure to add 2 constructors and a display() method. Do not include a main() method in the Teller class.

Test out this Teller class, by building a separate Tester class called TellerTester stored in a new file called --> "TellerTester.java". This TellerTester class will only have a main() method, that will instantiate a Teller object, pass all the data to the Teller constructor, and lastly call the Teller display() method; just these 3 lines.

public class Person {

// ========================== Properties ===========================

private String FirstName;

private String LastName;

private String Address;

private String Email;

//constructor with parameters

Person(String FirstName,String LastName,String Address,String Email) {

this.FirstName = FirstName;

this.LastName = LastName;

this.Address = Address;

this.Email = Email;

}

//constructor with no parameters

Person() {

this.FirstName = "";

this.LastName = "";

this.Address = "";

this.Email = "";

}

// ========================== Behaviors ==========================

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;

}

//method that displays person data

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);

} //end display()

//overriding toString method

public String toString() {

return "FirstName: "+getFirstName() + " LastName: "+getLastName() + " " +this.Address.toString()

+" Email: "+getEmail();

}

//main method

public static void main(String args []) {

Person p1;

p1 = new Person("Rodney","Duncan","70 Bowman St. South Windsor, CT 06074","rduncan@msn.com");

p1.display();

}

}

public class Employee extends Person {

private int id;

private double salary;

public Employee() {

super();

id = 0;

salary = 0;

}

public Employee(int id, String FirstName, String LastName, String Address, String Email, double salary) {

super(FirstName, LastName, Address, Email);

this.salary = salary;

this.id = id;

}

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public double getSalary() {

return salary;

}

public void setSalary(double salary) {

this.salary = salary;

}

public void display() {

super.display();

System.out.println("ld : " + this.id);

System.out.println("Salary : " + this.salary);

}

public static void main(String[] args) {

Employee e1;

e1 = new Employee(2323, "Bill", "Clinton", "Marietta", "bc@msn.com", 43000.00);

e1.display(); //prints all 6 properties

} //end main

} //end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!