Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Methods In this lab you will create and use methods in the Person class, including this special method, the constructor . Deliverable A zipped

Using Methods

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

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

Attributes

String firstName

String lastName

String hometown

String state

Constructorsone constructor with no input parameterssince 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

Methodspublic String toString()

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.out.println" 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

create a Person object called p2 using the two-parameter constructor with the value

firstName - Keaton

lastName - Ellis

create a Person object called p3 using the no-parameter constructor

display all the data from each object

Output

The output should be similar to

Person{firstName=Jillian, lastName=Jennings, hometown=Montclair, state=out-of-state} Person{firstName=Keaton, lastName=Ellis, hometown=N/A, state=N/A} Person{firstName=No, lastName=Name, hometown=N/A, state=N/A}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

What are three goals of inventory management?

Answered: 1 week ago