Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my previous code. Please add in this code. Assignment Objectives 1. Practice on creating and using Arrays as attributes and as input parameters.

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
This is my previous code. Please add in this code.
Assignment Objectives 1. Practice on creating and using Arrays as attributes and as input parameters. Keep practicing MVC. Deliverables A zipped Java project according to the How to submit Labs and Assignments guide. 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) Data 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, height=5'9", weight=180, hometown=Robbinsville, N.J., 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. 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. 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) o public ArrayList getData() View will overload basicDisplay o public void basic Display(String s) public void basicDisplay(ArrayList arr) w . 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, ho metown=Upper Marlboro, Md., highSchool=Dr. Henry A. W ise, Jr. } Person{name=Kyle Alston, height=5'9", weight=180, hom etown=Robbinsville, N.J., highSchool=Robbinsville} Person{name=Troy Apke, height=6'1", weight=220, homet own=Mt. Lebanon, Pa., highSchool=Mount Lebanon} Person{name=Matthew Baney, height=6'0", weight=225, h ometown=State College, Pa., highSchool=State College} Person{name=, height='6", weight=o, hometown=, highs chool=} 11:36 psu.instructure.com - Private The classes App it has the main method which is the method that Java looks for and runs to start any application o it creates 3 objects, one of the Model class, one of the View class and one of the Controller class. o 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 Model(); View view = new View(); Controller controller = new Controller(view, model); Controller 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 "intn" 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.basicDisplay (model.getData()); Model it has only one attribute, ArrayList persons o 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 overtog getDatat n) and returns . Model it has only one attribute, ArrayList persons o 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 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 o 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) o a toString() method Height 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 no 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=200, ho metown=Upper Marlboro, Md., highschool=Dr. Henry A. W ise, Jr.) Person{name=Kyle Alston, height=5'9", weight=180, hom etown=Robbinsville, N.J., highschool=Robbinsville) Person{name=Troy Apke, height=6'1", weight=220, homet own=Mt. Lebanon, Pa., highSchool-Mount Lebanon) Person{name=Matthew Baney, height=6'0", weight=225, h ometown=State College, Pa., highSchool=State College) Person{name=, height='0", weight=0, hometown=, highs chool=} package Model: public class Person private String names private Height height; private int weight; private String hometown private String highschool: 1o parameter Constructor publie person nana height-new Height() weight: hometowna"N/A highschool w/A" all parameters Constructor public Person(string name, Height height, int weight, String hometown, String highschool) this.name = name this.height = height: this.weight weight; this.hometown hometown this highschool - highschool; > 1/getters and setters public string gettame) { return names > public Height getHeight() return height: > public string getHometown return hometown } public String gettighschool() { return highschool: public void setName(string name) this.name name ) public void setHeight (Height height) this.height - height; ) public void set Hometown String howetown) { this.hometown - hometown public void sethighschool string highschool) { this.highschool - highschool; > publie int get weight() { return weight public void setWeight(int weight) this.weight - weight > override public String toString() { return "Person "name" name. height + height + weight weight hometown hometown High School + highschool + package Models public class Height private int feet private int inches 7o parte contractor puble Height) fet inchen PA II Parameter Contato publie Height fint tout, ist inches) this.fettet this. Inches Inches Pipettere puble Inter return foot public int que leches return inches public void settist feet) this feet feta puble void sechestnine) this.inches - inches > override public String return falschen package Models puble class Model /odel class will create 5 Personer Person Pl.:p).pt.po publie Model Loadta } public void loadstar pH w Parus Andes, del 3.2.200.Pretoria, ... Bryd., 22. Phew Person wyle Alstenneweight 5.3.190.invite... p} - new Toon Troy Apka Height6,1),220, Laban, Tants New Person Bey Height: (6,0,225, State Colle... See Se new : public String getDatain ) return pl.tostring le 2 return point else i return pi.totring les i return point) else i retur p.) w return invalid Input > > package Controller Import Model Model import View.View public class controller Model modeli View vivi puble Controller (View Model this. this. model www.bonicisplay model.getData view.banebisplayendeletta213 View.basisplay model.getData View.basiebiplaymode.getData www.baselaymodel.51) view.basleplay model.at package View; public class View { public View) { public void basicDisplay (String s) System.out.println(s); { } import Controller.Controller; import Model Model; import View.View; public class App public static void main(String[] args) { Model model - new Model(); View view = new View(); Controller controller = new Controller (view, model); > J/Output Person{name=Marcus Allen, height=5'2", weight=200, hometown=Upper Marlboro, Md., highschool=Dr. Henry A. Wise, Ir.} Person{name=kyle Alston, height=5'9", weight=180, hometown=Robbinsville, N.J., highschool=Robbinsville) Person{name=Troy Apke, height=6'1", weight=220, hometown=Mt. Lebanon, Pa., highschool=Mount Lebanon) Person{name=Hatthew Baney, height=6'8", weight=225, hometown=State College Pa., highschool=State College} Person{name=, height=&'&", weight=, hometown=N/A, highschool=N/A} invalid input parameter

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

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions