Question: Objects as Parameters In this lab you will create and use methods (that use Objects as Parameters) in the Person class. Deliverable A zipped NetBeans

Objects as Parameters

In this lab you will create and use methods (that use Objects as Parameters) in the Person class.

Deliverable

A zipped NetBeans project with 3 classes

App

Person

Height

Classes

Suggestion:

Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04.

Close Lab03.

Work on the new Lab04 project then.

The Person Class

Attributes

String firstName

String lastName

Height height

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

height - use the Height class no-parameter constructor

hometown - N/A

state - N/A

one constructor with three parameters

firstName using the input parameter

lastName using the input parameter

height using the input parameter

use the default values for

hometown - N/A

state - N/A

one constructor with all (five) 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.

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

The Height class

Attributes

int feet

int inches

Constructorsone constructor with no input parameterssince it doesn't receive any input values, you need to use the default values below:

feet - 5

feet - 6

one constructor with two parameters

feet using the input parameter

inches using the input parameter

MethodsString toString( )

toString( ) overrides the superclass Object toString( ) method

toString( ) returns information about this class attributes as a String

it returns a formatted String with feet and inches

for instance: 5'2"

The App class

create a Person object called p1 using the five-parameter constructor with the values

firstName - Jillian

lastName - Jennings

height - 5 7

hometown - Montclair

state - NJ

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

firstName - Keaton

lastName - Ellis

height 5 11

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, height=Height{5'7"}} Person{firstName=Keaton, lastName=Ellis, hometown=N/A, state=N/A, height=Height{5'11"}} Person{firstName=No, lastName=Name, hometown=N/A, state=N/A, height=Height{5'6"}}

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!