Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use a different code for plagerism public class Person { private String firstName; private String lastName; private String hometown; private String state; private Height

Please use a different code for plagerism

public class Person {

private String firstName;

private String lastName;

private String hometown;

private String state;

private Height height;

// Constructor with no input parameters

public Person() {

firstName = "No";

lastName = "Name";

hometown = "N/A";

state = "N/A";

height = new Height();

}

// Constructor with three parameters

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

this.firstName = firstName;

setLastName(lastName);

this.height = height;

hometown = "N/A";

state = "N/A";

}

// Constructor with all (five) parameters

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

this.firstName = firstName;

setLastName(lastName);

this.hometown = hometown;

this.state = state;

this.height = height;

}

// Getters and Setters

public String getFirstName() {

return firstName.substring(0, 1).toUpperCase() + firstName.substring(1).toLowerCase();

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName.toUpperCase();

}

public String getHometown() {

return hometown;

}

public void setHometown(String hometown) {

this.hometown = hometown;

}

public String getState() {

return state;

}

public void setState(String state) {

this.state = state;

}

public Height getHeight() {

return height;

}

public void setHeight(Height height) {

this.height = height;

}

// toString method

@Override

public String toString() {

String message;

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

message = "is from Pennsylvania";

} else {

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

}

return firstName + " " + lastName + " " + "from " + hometown + " " + message + " and their height is " + height;

}

// initials method

public void initials() {

String initial1 = firstName.substring(0, 1) + ".";

String initial2 = lastName.substring(0, 1) + ".";

System.out.println(initial1 + initial2);

}

// initials method overload

public void initials(int option) {

String result = "";

if (option == 1) {

result = getFirstName().substring(0, 1).toUpperCase() + "." + lastName;

} else if (option == 2) {

result = firstName + " " + getLastName().substring(0, 1).toUpperCase() + ".";

}

System.out.println(result);

}

}

public class Height {

private int feet;

private int inches;

// Constructor with no input 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;

}

// Getters and Setters

public int getFeet() {

return feet;

}

public void setFeet(int feet) {

this.feet = feet;

}

public int getInches() {

return inches;

}

public void setInches(int inches) {

this.inches = inches;

}

@Override

public String toString() {

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

}

}

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.toString());

System.out.println(p2.toString());

System.out.println(p3.toString());

}

}

image text in transcribedimage text in transcribedimage text in transcribed

Encapsulation In this lab you will start using enespeubtian in the Person and in the Height classes. Yau will also create a specint get methad and s special set method. Deliverable A zpped NetDesns praject with 3 classes - App - Persan - Height Classes Suggestion: - Use Netbeans to copy your last lab (Lab 04) to a new project called Lab05. - Close Lab04. - Work cn the new Lab05 project then. The Person Class - ises encopsulation - private attributes - get and set methods for each attrilsute 1. Attributes - String firstNarre - String listName - String hametcwn - String state - Height height 2. Constructors? - ane conatructor with no input parameters - since it doesn't receive amy input values, you need to use the default values belaw? - frsthivme - No - EstNarne-Name - hometown- N/A - state-N/S - height-ase the theight class na parameter conatructor - ane constructor with three parameters - firstName asing the input parameter - lastName using the input parameter - beight using the input parameter - tae the default values for - hometown-N/A - state-N/A - ane paratructor with all ifives parameters - cone input parameter for each attribute 3. Methods - Get and Set methods (a requirrement from encopsulatica) - important: - You shculd start generating the defiult get and set methods using NetBeans automatic generator - Then you wit change getFirst Name and setLast Name as specitied. - aetFirstName - returns first Name with the first letter in upper case and the remiaining of the String in lower case - Get methods should not charige the value of strributes - In this case it should not change/updhte the value of firstVame - getlistlvame - sethornetown - zetstate - getheight - setFistName - setlasthame - updater lastNanie to be al caps (all upper case) - remember to use setastName in all constructars so the data (the updated lastName, is stcred parrectly - sethometown - setstate - setheight - public String tostringld - returns this object as a String, ie, make each attribute a Strine concatenate all strigs and returnas one String - tustringll is a special methad, you will learn more about it in the neat lessans - it needs to be public - it needs to hove goverride natatian ian the line above the methad itselff. Netbeans will suggest you da it. - regarding state, the tostring method will have a simibr functicnality as Ape had in the first lab. - if the state attraute is "PA", display the abject's attritute name plus the message "is from Pennsyhania" - if the state attriaute is nat "PA", display the object's attribute name plus the mesoge" "is from out-of-state" - In short, the tastring0 methad returns all the data from exch object as a String - public void initisls[y - this method - gets frast Name and last Name - extract the initisis of each one of them - adds a "- period to each of them - and uses "System. out.printlin" to display them is crie String - public void initials int aption) - this method overloods public void initiobl i. This mesns, it hos the samie name, bat a uifferent rimber of parsmeters. - if the value of "aptian" 11 - gets firstName - extract its initials - adds a "- period to to a String - adds the botName ta this String- - and uses "Systernoutprintin" to display the String - if the value of "aptian" 12 - adds firstlame to a Strirg - getslastName - Extract its initials - addsa "- period to it - adds it to the String - and uses "Spstemout.printh" to displyy the String The Height class - Lses encapsulation - private attribates - get and set methods for each attribute- 1. Attributes - int feet - int inches 2. Constructers - ane panstructor with no input parameters - since it doesn't receive any input values, you need to use the default values belaw: - feet 5 - feet- 6 ane panstrictor with two parameters - feet using the input parameter - inches using the input parameter 3. Methods - public String taStringld - toStringi / overrides the supercloss Object toString[ ? methad - toStringl/ retums irformation about this dass attrbutes as a String - it returns a formatted String with feet and inches - for instance: 52 The Appclass - create a Person object callied p1 using the five-parameter canatructor with the walues - first Varre - jillian (see the different capitalization used to test the get/set methods) - batName-Jennings - height 57 - hemetown-Montelair - state-NJ 2, create a Person abject calked p2 using the three-parameter constructor with the value - firstVarre - KEATON (see the different capitalization used to test the get/set methods) - batharne-Eilis - height 511 3. create a Person abject called p3 using the no-parameter conatructer 4. displayall the dati from each abyect Output The output should be similar to

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions