In: Computer Science
Project 8-2: Person Manager
Create an application that lets you enter a new customer or a new employee.
Create a class named Person with these constructors and methods:
public Person(String first, String last)
public String getFirstName()
public void setFirstName(String first)
public String getLastName()
public void setLastName()
The Person class should override the toString() method so it returns the first name and last name in this format:
Name: Frank Jones
Create a class named Customer that inherits the Person class and contains these constructors and methods:
public Customer(String first, String last, String number)
public String getCustomerNumber()
public void setCustomerNumber(String number)
The Customer class should override the toString() method so it returns the value returned by the toString() method of the Person class appended with the customer number, like this:
Name: Frank
Jones
Customer Number: J54128
Create a class named Employee that inherits the Person class and contains these constructors and methods:
public Employee(String first, String last, String ssn)
public String getSsn()
public void setSsn(String ssn)
The getSsn() method should return a masked version of the social security number that only reveals the last four numbers.
The Employee class should override the toString() method so it returns the value returned by the toString() method of the Person class appended with the social security number, like this:
Name: Frank
Jones
SSN: xxx-xx-1111
class Person {
private String firstName;
private String lastName;
public Person(String aFirstName, String aLastName)
{
super();
firstName = aFirstName;
lastName = aLastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String aFirstName) {
firstName = aFirstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String aLastName) {
lastName = aLastName;
}
@Override
public String toString() {
return "Name : " +firstName + " "
+lastName;
}
}
class Customer extends Person {
private String customerNumber;
// constructor initialize the values using super
constructor
public Customer(String aFirstName, String aLastName,
String aCustomerNumber) {
super(aFirstName, aLastName);
customerNumber =
aCustomerNumber;
}
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String
aCustomerNumber) {
customerNumber =
aCustomerNumber;
}
//to string returns name and customer number
@Override
public String toString() {
return super.toString() +
"\nCustomerNumber: " + customerNumber;
}
}
class Employee extends Person {
private String ssn;
// constructor initialize the values using super constructor
public Employee(String aFirstName, String aLastName,
String aSs) {
super(aFirstName, aLastName);
ssn = aSs;
}
public String getSsn() {
return ssn;
}
public void setSsn(String aSs) {
ssn = aSs;
}
@Override
//to string returns name and ssn
public String toString() {
return super.toString() + "\nSSN: "
+ ssn;
}
}
public class TestPerson {
public static void main(String[] args) {
Person p1 = new Customer("Frank",
"Jones", "J54128");
Person p2 = new Employee("Frank",
"Jones", "XXXX-XXXX-1111");
System.out.println(p1);
System.out.println(p2);
}
}
Note : If you like my answer please rate and help me it is very Imp for me