Question
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)
- One class, one file. Don't create multiple classes in the same .java file
- Don't use static variables and methods
- Encapsulation: make sure you protect your class variables and provide access to them through get and set methods
- all the classes are required to have a constructor that receives all the attributes as parameters and update the attributes accordingly
- Follow Horstmann's Java Language Coding Guidelines
- 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
- using the full-parameter constructor with the data below
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
- ArrayList
- 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. "
- from Schildt's "Java: The Complete Reference, Eleventh Edition, 11th Edition":
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)
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
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 ArrayList
getData ( )(previously called the method getData (int n)) - ArrayList
getData without the "int n" parameter returns all objects in the ArrayList as Strings.
- ArrayList
- will pass the data to View, which will display it
- will retrieve data from Model using the model object to call now the method ArrayList
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
- it has only one attribute, ArrayList
- 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
- 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"
- String toString( )
- uses encapsulation
Output
The output will look like this:
LO1C LO1D . . app Person Height Creates model, view and controller objects String name int feet Height height Int inches Model int weight ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started