Question: Data The Model class will create 5 FootballPlayer objects which now have also number and position as attributes, besides their Person attributes 4 using the
Data
The Model class will create 5 FootballPlayer objects which now have also number and position as attributes, besides their Person attributes4 using the data below
name=Marcus Allen, height=5'2", weight=200, hometown=Upper Marlboro, Md., highSchool=Dr. Henry A. Wise, Jr., number=2, position=S
name=Kyle Alston, height=5'9", weight=180, hometown=Robbinsville, N.J., highSchool=Robbinsville, number=37, position=CB
name=Troy Apke, height=6'1", weight=220, hometown=Mt. Lebanon, Pa., highSchool=Mount Lebanon, number=28, position=S
name=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highSchool=State College, number=35, position=LB
1 using the no-parameter constructor
Functionality
This assignment is a follow up from the previous assignment with one update:
There is a new class FootballPlayer. FootballPlayer is a Person with some extra attributes.
Model will now store the FootballPlayer objects instead of Person objects.
The ArrayList should be then an ArrayList
You will keep the MVC functionality from the previous assignment
This new addition, of a specialized class FootballPlayer in Model, shows how the MVC architecture works. There will be changes in Model but Controller and View stay the same.
Controller will be simpler having only one line calling the new method in Model, getData(). This method returns an ArrayList
As in the previous assignment, the main objective is to make View display the information about the 5 objects (now footballPlayer instead of Person). These 5 objects are created in Model in the method loadData( ). Controller will retrieve the data from Model using the method getData() and pass it to View. View will use the method basicDisplay(ArrayList
Person{name=Marcus Allen, height=5'2", weight=200, hometown=Upper Marlboro, Md., highSchool=Dr. Henry A. Wise, Jr.} FootballPlayer{number=2, position=S} Person{name=Kyle Alston, height=5'9", weight=180, hometown=Robbinsville, N.J., highSchool=Robbinsville} FootballPlayer{number=37, position=CB} Person{name=Troy Apke, height=6'1", weight=220, hometown=Mt. Lebanon, Pa., highSchool=Mount Lebanon} FootballPlayer{number=28, position=S} Person{name=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highSchool=State College} FootballPlayer{number=35, position=LB} Person{name=, height=0'0", weight=0, hometown=N/A, highSchool=N/A} FootballPlayer{number=0, position=N/A} 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);
Controllerwill retrieve data from Model using the model object to call now the method getData ( )(previously called the method getData (int n))
getData without the "int n" parameter returns all objects in the ArrayList as Strings.
will pass the data to View, which will display it
no changes from the previous assignment
For instance, controller might look like this:
view.basicDisplay(model.getData());
Model
it needs an updated method, loadData( ), to load the data, now using an ArrayList to store the 5 FootballPlayer objects
it needs a updated method, getData(), to handle FootballPlayer instead of Person
View
it just needs to display the text data that it will receive from Controller
no changes from the previous assignment
Personuses 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
FootballPlayerhas the following attributes
int number;
String position;
two constructors one with no parametersuses the default values
number = 0
position = "N/A"
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
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 methodString 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.} FootballPlayer{number=2, position=S} Person{name=Kyle Alston, height=5'9", weight=180, hometown=Robbinsville, N.J., highSchool=Robbinsville} FootballPlayer{number=37, position=CB} Person{name=Troy Apke, height=6'1", weight=220, hometown=Mt. Lebanon, Pa., highSchool=Mount Lebanon} FootballPlayer{number=28, position=S} Person{name=Matthew Baney, height=6'0", weight=225, hometown=State College, Pa., highSchool=State College} FootballPlayer{number=35, position=LB} Person{name=, height=0'0", weight=0, hometown=N/A, highSchool=N/A} FootballPlayer{number=0, position=N/A} CODE IN java PLEASE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
