Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a new code do not re-use the one below Implementation in Java for the Height class : public class Height { int feet;

Please write a new code do not re-use the one below

Implementation in Java for the Height class :

public class Height {

int feet;

int inches;

// Constructor with no parameters

public Height() {

this.feet = -5;

this.inches = 6;

}

// Constructor with two parameters

public Height(int feet, int inches) {

this.feet = feet;

this.inches = inches;

}

@Override

public String toString() {

return feet + "' " + inches + "''";

}

}

Implementation in Java for the Person class:

public class Person {

String firstName;

String lastName;

Height height;

String hometown;

String state;

// Constructor with no parameters

public Person() {

this.firstName = "No";

this.lastName = "Name";

this.height = new Height();

this.hometown = "N/A";

this.state = "N/A";

}

// Constructor with three parameters

public Person(String firstName, String lastName, Height height) {

this.firstName = firstName;

this.lastName = lastName;

this.height = height;

this.hometown = "N/A";

this.state = "N/A";

}

// Constructor with all parameters

public Person(String firstName, String lastName, Height height, String hometown, String state) {

this.firstName = firstName;

this.lastName = lastName;

this.height = height;

this.hometown = hometown;

this.state = state;

}

@Override

public String toString() {

String location;

if (state.equals("PA")) {

location = "is from Pennsylvania";

} else {

location = "is from out-of-state";

}

return "Person (firstName-" + firstName + ", lastName-" + lastName +

", hometown-" + hometown + ", state-" + location + ", height-" + height + ")";

}

}

Implementation in Java for the App class :

public class App {

public static void main(String[] args) {

Person p1 = new Person("Jillian", "Jennings", new Height(5, 7), "Montclair", "NJ");

Person p2 = new Person("Keaton", "Ellis", new Height(5, 11));

Person p3 = new Person();

System.out.println(p1);

System.out.println(p2);

System.out.println(p3);

}

}

image text in transcribedimage text in transcribed

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 1. Attributes - String firstName - String lastName - Height height - 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 - 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 3. Methods - public String toString() - returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String. - toString0 is a special method, you will leam 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(l method retums all the data from each object as a String The Height class 1. Attributes - int feet - int inches 2. Constructors - one constructor with no input parameters - since it doesn't receive any input values, you need to use the default values below: - feet 5 - inches-6 - one constructor with two parameters - feet using the input parameter - inches using the input parameter 3. Methods - String 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 The App class - create a Person object called p1 using the five-parameter constructor with the values - firstName - Jillian - lastName-Jennings - height 57 - hometown-Montclair - state-NJ 2. create a Person object called p2 using the three-parameter constructor with the value - firstName - Keaton - lastName-Ellis - height 511 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-Jilian, lastWame-Jennings, hometown-Montclair, state-cut-of-state, height-Height {5}}} PersonffirstNane-Keaton, lastNane-Ellis, horetown-N/A, state-N/A, hoight-Height {511}} PersonffirstNane-No, lastNanc-Nanc, honctown-N/A, stste-N/A, height-Height {56}}

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

Step: 3

blur-text-image

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago