Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

O.O. Requirements (these items will be part of your grade) One class, one file. Don't create multiple classes in the same .java file Don't use

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)
    • 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 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)
    • public ArrayList getData()
  • View will overload basicDisplay
    • public void basicDisplay(String s)
    • public void basicDisplay(ArrayList arr)

image text in transcribedAs 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:

image text in transcribed

The classes

  • App
    • 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 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, controller might look 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, 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
    • 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;
    • has two constructors
      • one with no parameters
      • one with all the parameters (one for each attribute)
    • a toString( ) method
    Height
    • it is a class (or type) which is used in Person defining the type of the attribute height
    • 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:

image text in transcribed

LO1C LO1D . . app Person Height Creates model, view and controller objects String name int feet Height height Int inches Model int weight ArrayListgetData All parameter Private attributes Get and set methods Controller Encapsulation Model mode! View view Person[name-Marcus Allen, heigh-52", weight-200, hometown-Upper Marlboro, Md., high School Dr. Henry A. Wise, Jr.} Get and set methods Modified to display . All parameter constructor 999" String toString() View No parameter constructor Methods void basicDisplay(Strings) vold basicDisplay(ArrayList arr) app Person Creates model, view and controller objects String name Height height Model int weight ArrayList persons String hometown No parameter constructor String highSchool Methods void loadData() Two constructors String getData(int n) No parameter ArrayList getData() All parameter Controller . . capsulation Model mod Personname-Marcus Allen, height=5*2", weight poo, hometown Upper! View view Person name-Kyle Alston, height59", weight=18 hometown-Robbinsvi Person name=Troy Apke, height=6'1", weight=220 hometown=Mt. Lebane All paramet Person name=Matthew Baney, height=60", weight=225, hometown State Person name Saquon Barkley, height 5'11", weight-222, hometown Cop View No parameter constructor Methods void basicDisplay(Strings) void basicDisplay(ArrayList arr) 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=Robbi nsville} Person{name=Troy Apke, height=6'1", weight=220, hometown=Mt. Lebanon, Pa., highschool=Mount Leb anon} Person{name=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highschool=sta te College} Person{name=, height='0", weight=0, hometown=, highschool=} 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.)., 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, hometowns, 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

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions