Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use this code for person and app. follow all the steps below to create the code. make sure its correct. Person Class: public class

please use this code for person and app. follow all the steps below to create the code. make sure its correct.
Person Class:
public class Person{
private String name;
private int weight;
private String hometown;
private String highSchool;
public Person(){
this.name="";
this.weight=0;
this.hometown="N/A";
this.highSchool="N/A";
}
public Person(String name, int weight, String hometown, String highSchool) {
this.name = name;
this.weight = weight;
this.hometown = hometown;
this.highSchool = highSchool;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getHometown() {
return hometown;
}
public void setHometown(String hometown) {
this.hometown = hometown;
}
public String getHighSchool() {
return highSchool;
}
public void setHighSchool(String highSchool) {
this.highSchool = highSchool;
}
@Override
public String toString() {
return "Person{" + "name=" + name + ", weight=" + weight + ", hometown=" + hometown + ", highSchool=" + highSchool + '}';
}
}
App Class:
public class App {
public static void main(String[] args){
Person p1=new Person("Marcus Allen",200,"Upper Marlboro, Md.","Dr. Henry A. Wise, Jr.");
Person p2=new Person("Kyle Alston",180,"Robbinsville, N.J.","Robbinsville");
Person p3=new Person("Troy Apke",220,"Mt. Lebanon, Pa.","Mount Lebanon");
Person p4=new Person("Matthew Baney",225,"State College, Pa.","State College");
Person p5=new Person();
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.println(p4);
System.out.println(p5);
}
}
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
O.O. Requirements (these items will be part of your grade) 1. One class, one file. Don't create multiple classes in the same java file 2. Don't use static variables and methods 3. Encapsulation: make sure you protect your class variables and provide access to them through get and set methods 4. all the classes are required to have a constructor that receives all the attributes as parameters and update the attributes accordingly 5. Follow Horstmann's Java Language Coding Guidelines 6. Organized in packages (MVC - Model - View Controller) Contents . app Gess model and controller objects Height Int feet Int inches Person String name Height height int weight String hometown String high school Two constructor No parameter All parameter Model Amaterson persons No permite constructor Methods vold ladata Sering Detin ArrayLiscripta Two constructors No parameter All parameter Encapsulation Private attributes Get and set methods Controller Model model View view Encapsulation Private attributes Get and set methods String toString) String toString Modified to display 999 All parameter constructor View No parameter constructor Methods void basic playering vold has play(Arrayurpar) Data I The Model class will create 5 Person objects (same as last assignment) o using the full-parameter constructor with the data below name=Marcus Allen, height 5'2", weight-200, hometown-Upper Marlboro, Md., highSchool-Dr. Henry A. Wise, Jr. name-Kyle Alston, height5'9", weight-180, hometown=Robbinsville, NJ. HighSchool-Robbinsville name=Troy Apke, height=6'1", weight-220, hometown=Mt. Lebanon, Pa., highSchool-Mount Lebanon name-Matthew Baney, height=6'0", weight-225, hometown-State College, Pa, highSchool-State College o using the no-parameter constructor Functionality This assignment is a follow up from the previous assignment with a major update: Model will store the Person objects in an ArrayList instead of using individual variables. ArrayList persons is the only attribute in Model . You will also use the concept of method overloading, which you have seen in the beginning of Chapter 7 o from Schildt's "Java: The Complete Reference, Eleventh Edition, 11th Edition": . "In Java, it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading." You will keep the MVC functionality from the previous assignment Controller will be simpler having only one line calling the new method in Model. ArrayList getData(). This method returns an ArrayList with one line (one big String) for each person in the ArrayList. Idol will need to have an updated loadData() because the Person objects are now stored in an Controller will be simpler having only one line calling the new method in Model, ArrayList getData(). This method returns an ArrayList with one line (one big String) for each person in the ArrayList. Model will need to have an updated loadData() because the Person objects are now stored in an ArrayList. . Model will also overload getData public String getData(int n) public ArrayList arr) O LOC 1010 As in the previous assignment, the main objective is to make View display the information about the 5 Person objects. These 5 objects are created in Model in the method loadData(). Controller will retrieve the data from Model using the method ArrayList getData() and pass it to View. View will use the method void basicDisplay(ArrayList arr) to display data from each object with the following result: Person{name-Marcus Allen, height=5'2", weight-200, hometown-Upper Marlboro, Md., highSchoolD r. Henry A. Wise, Jr. } Person[name-Kyle Alston, height 5'9", weight-180, hometown-Robbinsville, N.J., highSchool Robb inulle inht770. hometown.Mt. Lebanon, Pa., highschool Mount Le The classes App o it has the main method which is the method that Java looks for and runs to start any application . it creates 3 objects, one of the Model class, one of the View class and one of the Controller class. When it creates Controller, it passes the two other objects as input parameters so that Controller has access to Model and View. Model model - new Modelo: View view = new Vieto: Controller controller new Controller(view, model); Controller o will retrieve data from Model using the model object to call now the method ArrayListgetData (previously called the method getData(int n)) ArrayList getData without the "int n" parameter returns all objects in the ArrayList as Strings. o will pass the data to View, which will display it For instance, controller might look like this: view.basicDisplayCmodel.getData(); Model o it has only one attribute, ArrayList getData, which overloads String getData(int n) and muman ArrayList of String with one big String for each person object in the array For instance, controller might look like this: view.basicDisplay model.getData(): Model o it has only one attribute. ArrayList persons . it uses encapsulation o it needs an updated method, loadData), to load the data, now using an ArrayList to store the 5 Person objects o it needs a method, ArrayList getData(), which overloads String getData(int n) and returns an ArrayList of String with one big String for each person object in the array View o it just needs to display the text data that it will receive from Controller It needs an overloaded method, void basicDisplay (String s). The new method receives an ArrayList of Strings and displays each String in a new line, it will be void basicDisplay(ArrayList arr) Person uses encapsulation private attributes a get and a set method for each attribute has the following attributes . String name: Height height: int weight; String hometown: String highSchool: o has two constructors . one with no parameters - one with all the parameters (one for each attribute) a toString() method o it is a class (or type) which is used in Person defining the type of the attribute height o uses encapsulation - private attributes - a get and a set method for each attribute o it has two attributes . int feet int inches o two constructors one with rio parameters one with all the parameters (one for each attribute) o and a method . 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'2" Output The output will look like this: Person{name-Marcus Allen, height 5'2", weight-280, hometown-Upper Marlboro, Md., highschool- r. Henry A. Wise, Jr.) Person[name-Kyle Alston, height 5'9", weight=180, hometown-Robbinsville, N.J., highschool Robb insville) Person[name-Troy Apke, height 6'1", weight 220, hometown Mt. Lebonon, Pa., highSchool Mount Le banon) Person[nome-Matthew Baney, height 6'0", weight-225, honetown-State College, Po.. highschool-St ate College] Person[name-, height", weight, hometowne, highSchool)

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

More Books

Students also viewed these Databases questions