Answered step by step
Verified Expert Solution
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);
}
}
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