Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Model class will create 5 Person objects using the full-parameter constructor with the data below name=Marcus Allen, height=5'2, weight=200, hometown=Upper Marlboro, Md.,

 The Model class will create 5 Person objects

  •  
  • 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
    •  
  •  
  •  
  • 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 isthe only attributein Model
  • You will also use the concept of methodoverloading, 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 updatedloadData( )because thePersonobjects are now stored in an ArrayList.
  • Model will alsooverload getData
    • publicStringgetData(int n)
    • publicArrayListgetData()
  • View willoverload basicDisplay
    • public void basicDisplay(String s)
    • public void basicDisplay(ArrayList arr)


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., highSchool=Dr. Henry A. Wise, Jr.} 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=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highSchool=State College} Person{name=, height=0'0", weight=0, hometown=, highSchool=}The classes

  • App
    • it has themainmethod 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 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 "int n" parameter returns all objects in the ArrayList as Strings.
    • will pass the data to View, which will display it

For instance, controllermightlook like this:

view.basicDisplay(model.getData());

  • Model
    • it has only one attribute, ArrayList persons
    • it uses encapsulation
    • it needs an updated method,loadData( ), to load the data, now using an ArrayList to store the 5 Person objects
    • it needs a method,ArrayListgetData(), whichoverloadsString 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, voidbasicDisplay (String s). The new method receives an ArrayList of Strings and displays each String in a new line, it will bevoid basicDisplay(ArrayList arr)
  • Person
    • uses encapsulation
      • private attributes
      • a get and a set method for each attribute
    • has the following attributes
      • String name;
      • Heightheight;
      • int weight;
      • String hometown;
      • String highSchool;
    • has two constructors
      • one with no parameters
      • one with all the parameters (one for each attribute)
    • a toString( ) method

    • it is a class (or type) which is used in Person defining the type of the attributeheight
    • uses encapsulation
      • private attributes
      • a get and a set method for each attribute
    • it has two attributes
      • int feet;
      • int inches
    • two constructors
      • one with no parameters
      • one with all the parameters (one for each attribute)
    • 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, hometown=Upper Marlboro, Md., highSchool=Dr. Henry A. Wise, Jr.} 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=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highSchool=State College} Person{name=, height=0'0", weight=0, hometown=N/A, highSchool=N/A}







Step by Step Solution

There are 3 Steps involved in it

Step: 1

To implement the described functionality you would need to create the classes as described Model View Controller Person and Height Heres a basic imple... 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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions