Question
1. Create a class called Person with the following properties: x The Person class should have getters and setters for all properties other than id.
1. Create a class called Person with the following properties: x The Person class should have getters and setters for all properties other than id. (Use Eclipse to help you auto-generate these.) x Person class should also have a getter for id x In addition to these getters and setters, Person should have the following instance methods: x toString returns full name, like "Edgar Allen Poe" x getEmailDomain returns the domain portion of an email (after the @), as in "xyz.com" x getLast4SSN returns the last four digits of the Social Security Number x Add some validation to age, email and ssn. You may have done this via the setters in the past. However, this time, let's add class (static) methods to validate these fields as best you can. Give some thought to what advantages this approach would have.
2. Create a driver program PersonApp to test the class x Prompt user for all Person properties except id. You can hardcode any id you like, but use the id as the HashMap key. x Accept any value for the name fields x Only accept valid values for age, email and ssn x Create a Person with the valid input
3. Notes on validation. Here is a list of validation checks you can perform. Some are easier to implement than others, and there are many ways to correctly validate these aspects of the fields. Implement as many as you can. Age entered by user x Must be an integer greater than 16 Email address string entered by user x String must contain a '@' and at least one '.' x A '.' must follow the '@' x String must only contain one '@' Social Security Number string entered by user x String must contain two '-' characters in the correct position x The length of the string must be 11 x String must contain only digits or numbers. If you encounter invalid data, log it using the logging API of Java. (Do not use System.out.println(); ) Property Data Type id Integer firstName String middleName String lastName String email String ssn String age Integer
4. Static variables x Keep track of the highest age entered for a Person in a static variable.
5. Create subclasses for Instructor and Student x Instructors should have a Department x Students should have a Major x Generate getters and setters.
6. Add the Person, the Student and the Instructor to a HashMap. x In the driver program, create a Student and an Instructor (you don't need to prompt for input) x Add these three instances to a HashMap
7. Output the following after creating each person: x Loop through the HashMap and display x The person's full name and what kind of Person are they x The person's email domain x The last 4 digits of the person's Social Security Number x Whether the person is the oldest in the collection x The major for the Student, the department for the Instructor
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started