Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago

Question

8. Measure the effectiveness of the succession planning process.

Answered: 1 week ago