Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab you will create and use methods in the Person class, including this special method, the constructor. Deliverable A zipped NetBeans project with
In this lab you will create and use methods in the Person class, including this special method, the constructor. Deliverable A zipped NetBeans project with 2 classes - App - Person Classes \begin{tabular}{|l|l|} \hline \multicolumn{1}{|c|}{ App } \\ \hline - Creates a Person object p1 using the four-parameter constructor. \\ - Creates a Person object p2 using the two-parameter constructor. \\ - Creates a Person object p3 using the no-parameter constructor. \\ - Uses the method toString() to display the data from the 3 objects \end{tabular} Suggestion: - Use Netbeans to copy your last lab (Lab 02) to a new project called Lab03. - Close Lab02. - Work on the new Lab03 project then. The Person Class 1. Attributes - String firstName - String lastName - String hometown - String state 2. Constructors - one constructor with no input parameters - since it doesn't receive any input values, you need to use the default values below: - firstName - No - lastName - Name - hometown - N/A - state - N/A - one constructor with two parameters - firstName using the input parameter - lastName using the input parameter - use the default values for - hometown - N/A - state - N/A - one constructor with all (four) parameters - one input parameter for each attribute 3. Methods - public String toString0) - returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String. - toString() is a special method, you will learn more about it in the next lessons - it needs to be public - it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it. - regarding state, the toString method will have a similar functionality as App had in the first lab but with an update to account for the new possible value "N/A. - if the state attribute is "N/A", display the value as it is "N/A". - if the state attribute is "PA", display the object's attribute name plus the message "is from Pennsylvania" - if the state attribute is not "PA", display the object's attribute name plus the message "is from out-of-state" - In short, the toString() method returns all the data from each object as a String - public void initials() - this method - gets firstName and lastName - extract the initials of each one of them - adds a "." period to each of them - and uses "System.out.println" to display them as one String - public void initials( int option) - this method overloads public void initials(). This means, it has the same name, but a different number of parameters. - if the value of "option" is 1 - gets firstName - extract its initials - adds a "." period to to a String - adds the lastName to this String - and uses "System.out.println" to display the String - if the value of "option" is 2 - adds firstName to a String - gets lastName - extract its initials - adds a ". period to it - adds it to the String - and uses "System.outprintln" to display the String The App class - create a Person object called p1 using the four-parameter constructor with the values - firstName - Jillian - lastName - Jennings - hometown-Montclair - state - NJ 2. create a Person object called p2 using the two-parameter constructor with the value - firstName - Keaton - lastName - Ellis 3. create a Person object called p3 using the no-parameter constructor 4. display all the data from each object Output The output should be similar to Person\{firstNane= Jillan, 1astNane=Jennings, hometown=Montclair, state=out-of-state\} Person\{firstNane=Keaton, 1 astName=E11ls, hometown=N/A, state=N/A\} Person\{firstNane-No, las tName=Nane, honetown=N/A, state=N/A
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