Solution :
App.java:
import Controller.Controller;
import Model.Model;
import View.View;
public class App
{
public static void main(String[] args) // Main method
{
Model model = new Model(); // Creates model object.
View view = new View(); // Creates view object.
Controller controller = new Controller(view, model); // Creates controller object that accepts view and model objects.
}
}
package Controller;
import View.View;
{
Model model; // Model object
View view; // View object
public Controller(View v, Model m) // Method that imports both model and view classes as objects.
{
model = m;
view = v;
//view.basicDisplay(model.getData()); // basicDisplay method from View class prints FootballPlayer objects as Strings from Model class.
view.basicDisplay(model.getMembers().get(1).getAttributeName(3));
view.basicDisplay(model.getMembers().get(1).getAttribute(3));
view.basicDisplay(model.getMembers().get(1).getAttributeNames());
view.basicDisplay(model.getMembers().get(1).getAttributes());
view.basicDisplay("size of names=" + model.getMembers().get(1).getAttributeNames().size());
view.basicDisplay("size of attributes=" + model.getMembers().get(1).getAttributes().size());
}
}
FootballPlayer.java:
package Model;
import java.util.ArrayList;
public class FootballPlayer extends Person implements TableMember { // Used "extends" keyword to inherit attributes from superclass Person, while using "implements" to implement methods from TableMember interface.
private int number; // Creating private attribute for int number.
private String position; // Creating private attribute for String position.
public FootballPlayer(String name, int feet, int inches, int weight, String hometown, String highSchool, int number, String position) // Full parameter constructor for FootballPlayer object (using "super" keyword to incorporate attributes from superclass).
{
super(name, feet, inches, weight, hometown, highSchool); // Used super keyword to include attributes from superclass.
this.number = number; // Value assigned from getNumber method to private number instance variable for FootballPlayer object.
this.position = position; // Value assigned from getPosition method to private position instance variable for FootballPlayer object.
}
public FootballPlayer() // No parameter constructor for FootballPlayer object.
{
this.number = 0; // Default value assigned to private number instance variable under no parameter constructor for FootballPlayer object.
this.position = "N/A"; // Default value assigned to private position instance variable under no parameter constructor for FootballPlayer object.
}
Override
public String getAttribute(int n) // getAttribute method that is implemented from interface.
{
switch (n) { // Switch statement for each attribute from each FootballPlayer object. Including two local attributes, denoted by this. While the others are denoted by "super".
case 0:
return String.valueOf(this.number); // Use of the dot operator allowed me to discover String.valueOf method to output int attributes as a string.
case 1:
return this.position;
case 2:
return super.getName();
case 3:
return super.getHeight().toString();
case 4:
return String.valueOf(super.getWeight());
case 5:
return super.getHometown();
case 6:
return super.getHighSchool();
default:
return ("invalid input parameter");
}
}
Override
public ArrayList<String> getAttributes() // getAttributes ArrayList method that is implemented from interface.
{
ArrayList<String> getAttributes = new ArrayList<>();
for(int i = 0; i <= 6; i++){ // For loop to add each attribute to the getAttributes ArrayList from getAttributes method.
getAttributes.add(getAttribute(i));
}
return getAttributes;
}
Override
public String getAttributeName(int n) // getAttributeName method implemented from interface.
{
switch (n) { // Switch statement for the name of each attribute from each FootballPlayer object.
case 0:
return "number";
case 1:
return "position";
case 2:
return "name";
case 3:
return "height";
case 4:
return "weight";
case 5:
return "hometown";
case 6:
return "highSchool";
default:
return ("invalid input parameter");
}
}