Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE FOLLOW ALLL INSTRUCTIONS PLEASE DO IT STEP BY STEP PLEASE USE THE CODE BELOW import Controller.Controller; import Model.Model; import View.View; //App class with main()

PLEASE FOLLOW ALLL INSTRUCTIONS
PLEASE DO IT STEP BY STEP
PLEASE USE THE CODE BELOW
import Controller.Controller;
import Model.Model;
import View.View;
//App class with main()
public class App {
public static void main(String[] args) {
Model model = new Model();
View view = new View();
Controller controller = new Controller(view,model);
}
}
package Controller;
import Model.Model;
import View.View;
public class Controller {
Model model;
View view;
public Controller(View v, Model m) {
this.model = m;
this.view = v;
view.basicDisplay(model.getData(1));
view.basicDisplay(model.getData(2));
view.basicDisplay(model.getData(3));
view.basicDisplay(model.getData(4));
view.basicDisplay(model.getData(5));
view.basicDisplay(model.getData(6));
}
}
package Model;
public final class Model {
/*Model class will create 5 Persons*/
Person p1,p2,p3,p4,p5;
public Model()
{
//call loadData()
//in Model() constructor
loadData();
}
public void loadData()
{
//using full parameterised constructor
p1= new Person("Marcus Allen",200,"Upper Marlboro, Md.","Dr. Henry A. Wise, Jr.");
p2 = new Person("Kyle Alston",180,"Robbinsville, N.J.","Robbinsville");
p3 = new Person("Troy Apke",220,"Mt. Lebanon, Pa.","Mount Lebanon");
p4 = new Person("Matthew Baney",225,"State College Pa.","State College");
//using no parameter constructor
p5= new Person();
}
/*
Controller will retrieve the data from model using
this method
*/
public String getData(int n)
{
switch (n) {
case 1:
return p1.toString();
case 2:
return p2.toString();
case 3:
return p3.toString();
case 4:
return p4.toString();
case 5:
return p5.toString();
default:
return "invalid input parameter";
}
}
}
package Model;
public class Person{
private String name;
private int weight;
private String hometown;
private String highSchool;
public Person(){
this.name="";
this.weight=0;
this.hometown="N/A";
this.highSchool="N/A";
}
public Person(String name, int weight, String hometown, String highSchool) {
this.name = name;
this.weight = weight;
this.hometown = hometown;
this.highSchool = highSchool;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getHometown() {
return hometown;
}
public void setHometown(String hometown) {
this.hometown = hometown;
}
public String getHighSchool() {
return highSchool;
}
public void setHighSchool(String highSchool) {
this.highSchool = highSchool;
}
@Override
public String toString() {
return "Person{" + "name=" + name + ", weight=" + weight + ", hometown=" + hometown + ", highSchool=" + highSchool + '}';
}
}
package View;
public class View {
public View()
{
}
public void basicDisplay(String s)
{
System.out.println(s);
}
}
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
y Resources iments VID Schedule Assignment Objectives 1. Practice on implementing inheritance in Java o Football Player will extend Person 2. Overriding methods toString, which is a method from the Object class, is being overriden since lesson 01. In the Inheritance lesson you will understand what it means to override a method, . If you click on the link above you will find this definition (taken from the Object class) toString Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It i s recommended that all subclasses override this method Deliverables A zipped Java project according to the How to submit Labs and Assicaments guide 0.0. 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. All the classes are required to have an "empty constructor that receives no parameters but updates all the attributes as needed 6. Follow Horstmann's Java Language Coding Guidelines 7. Organized in packages (MVC - Model - View Controller) Contatti Contents app Creates model, view and controller objects Height int feet Int inches Person String name Height height Int weight String hometown String highSchool Model ArrayList Football player players No parameter constructor Methodis vold loadData) String eetDatalin ArrayList instead of the previous 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 with one line (one big String) for each person in the 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 arr) to display data from . metou Toubacar controller will retrieve the data from Moderusing the method gewacay and pass it to View.View will use the method 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- r. Henry A. Wise, Jr.) Football Player(number-2, position-S} Person{name-Kyle Alston, height 5'9", weight-180, hometown.Robbinsville, N.J., highschool-Robb insville) Football Player(number-37, position-CB} Person {name-Troy Apke, height 6'1", weight-220, hometown.Mt. Lebanon, Pa., highschool-Mount Le banon) FootballPlayer{number-28, position-S} Person[name Matthew Baney, height-6'0", weight-225, hometown-State College, Pa., highschool-St ate College FootballPlayer{number-35, position=LB} Person{namem, height='0", weight-, hometown-N/A, highschool.N/A] FootballPlayer{number, po sition-NA} The classes . The classes App o 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 o will 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. o will pass the data to View, which will display it no changes from the previous assignment TOPCOMIS For instance, controller might look like this: view.basicDisplayCmodel.getData(); Model o it needs an updated method, loadData(), to load the data, now using an ArrayList to store the 5 Football Player objects o it needs a updated method, getData(), to handle FootballPlayer instead of Person View o it just needs to display the text data that it will receive from Controller o no changes from the previous assignment 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 FootballPlayer o has the following attributes . int number: String position; o two constructors one with no parameters uses the default values one with no parameters uses the default values number = 0 . position - "N/A . 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 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, hometown=Upper Marlboro, Md, highSchool-Or Henry A. Wise, r.) Football Player(number-2, position-S} Person{name-kyle Alston, height 5'9", weight-180, hometown Robbinsville, N.J., highschool-Robbinsville) Football layer(number-37, position=CB) Person{name-Troy Apke, height 6'1". weight-220, hometowNt. Lebanon, Pa., highschool-Mount Lebanon) Football Play er {number=28, position-S} Person{name Matthew Boney..height 6'8". weight-225, hometown State College, Pa.. highSchool-State College Footba 11Player(number 35, position-LB) Person[name-, height='8", weight-, hometown N/A, highSchool WA} Football Player(number, position W/A}

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

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

How does EVA differ from residual income?

Answered: 1 week ago