The Interface
- it is an interface
- remember the interface definition
-
Interfaces are often compared to a contract, to a promise to implement the methods described in the interface. An interface in Java does not have any real code for implementation of its methods, it has only the skeleton of the methods. When a class decides to implement an interface, it has to contain the real code for each method in the interface.
- These are the four methods that FootballPlayer has to implement
-
public String getAttribute(int n); Returns the value of a specific attribute. The input parameter start with 0 for the first attribute, then 1 for the second attribute and so on.
-
public ArrayList getAttributes(); Returns the value of all attributes as an ArrayList of Strings.
-
public String getAttributeName(int n); Returns the name of a specific attribute. The input parameter start with 0 for the first attribute, then 1 for the second attribute and so on.
-
public ArrayList getAttributeNames(); Returns the name of all attributes as an ArrayList of Strings. the abstract methods are
Do not use the scanner class or any other user input request. You application should be self-contained and run without user input. Assignment Objectives 1. Practice on implementing interfaces in Java o Football Player will implement the interface Table Member 2. Overriding methods o when Football Player implements TableMember, Football Player will have to write the real Java code for all the interface abstract methods Deliverables A zipped Java project according to the How to submit Labs and Assignments guide. O.O. 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) Contents TableMember Person String name Height height int weight String hometown String highSchool public String getAttribute(int n); public ArrayList
getAttributes(); public String getAttributeName(int n); public ArrayList getAttributeNames(); String toString() extends implements Football Player Height int feet int inches int number String position String toString() {...} public String getAttribute(int n){...} public ArrayListgetAttributes() {...} public String getAttributeName(int n) {...} public ArrayListgetAttributeNames() {...} String toString() FootballPlayer will implement the interface TableMember writing real code for all the abstract methods. app Model model = new Model(); Model Football player fp = new Football Player(2, "Marcus Allen", ....); Sys...println(fp.getAttributes().toString(); for (int i = 0; i Model > Search Results Output - A03_Solution_Football Player TableMember (run) run: [Marcus Allen, 6'2", 209, Upper Marlboro, MD, Dr. Henry A. Wise, 2, 5] [Marcus Allen, 6'2", 209, Upper Marlboro, MD, Dr. Henry A. Wise, 2, 5] = name - Marcus Allen 1 = height - 6'2" 2 = weight - 209 3 = hometown - Upper Marlboro, MD 4 = highSchool - Dr. Henry A. Wise 5 = number - 2 6 = position - S [name, height, weight, hometown, highschool, number, position) [name, height, weight, hometown, highSchool, number, position) BUILD SUCCESSFUL (total time: 0 seconds) o it creates a Football Player object o uses this object to test and display the result of the newly implemented methods getAttribute(int n) getAttributes() .getAttributeName(int n) getAttributeNames() Person o has the following attributes String name; Height height; int weight; String hometown; String highSchool; o and a method String toString() .toString() overrides the superclass Object toString() method .toString() returns information about this class attributes as a String o encapsulation if you want other classes in the same package yo have access to the attributes, you need to make them protected instead of private. I see more about encapsulation here. Football Player o has the following attributes int number; String position; o has the following method from the previous lab String toString() .toString() overrides the superclass Object toString() method .toString() returns information about this class attributes as a String o and the methods coming from the interface Table Member getAttribute(int n) getAttributes() .getAttributeName(int n) getAttributeNames() Height o it is a class (or type) which is used in Football Player defining the type of the attribute height o it has two attributes int feet; int inches 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" Do not use the scanner class or any other user input request. You application should be self-contained and run without user input. Assignment Objectives 1. Practice on implementing interfaces in Java o Football Player will implement the interface Table Member 2. Overriding methods o when Football Player implements TableMember, Football Player will have to write the real Java code for all the interface abstract methods Deliverables A zipped Java project according to the How to submit Labs and Assignments guide. O.O. 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) Contents TableMember Person String name Height height int weight String hometown String highSchool public String getAttribute(int n); public ArrayListgetAttributes(); public String getAttributeName(int n); public ArrayList getAttributeNames(); String toString() extends implements Football Player Height int feet int inches int number String position String toString() {...} public String getAttribute(int n){...} public ArrayListgetAttributes() {...} public String getAttributeName(int n) {...} public ArrayListgetAttributeNames() {...} String toString() FootballPlayer will implement the interface TableMember writing real code for all the abstract methods. app Model model = new Model(); Model Football player fp = new Football Player(2, "Marcus Allen", ....); Sys...println(fp.getAttributes().toString(); for (int i = 0; i Model > Search Results Output - A03_Solution_Football Player TableMember (run) run: [Marcus Allen, 6'2", 209, Upper Marlboro, MD, Dr. Henry A. Wise, 2, 5] [Marcus Allen, 6'2", 209, Upper Marlboro, MD, Dr. Henry A. Wise, 2, 5] = name - Marcus Allen 1 = height - 6'2" 2 = weight - 209 3 = hometown - Upper Marlboro, MD 4 = highSchool - Dr. Henry A. Wise 5 = number - 2 6 = position - S [name, height, weight, hometown, highschool, number, position) [name, height, weight, hometown, highSchool, number, position) BUILD SUCCESSFUL (total time: 0 seconds) o it creates a Football Player object o uses this object to test and display the result of the newly implemented methods getAttribute(int n) getAttributes() .getAttributeName(int n) getAttributeNames() Person o has the following attributes String name; Height height; int weight; String hometown; String highSchool; o and a method String toString() .toString() overrides the superclass Object toString() method .toString() returns information about this class attributes as a String o encapsulation if you want other classes in the same package yo have access to the attributes, you need to make them protected instead of private. I see more about encapsulation here. Football Player o has the following attributes int number; String position; o has the following method from the previous lab String toString() .toString() overrides the superclass Object toString() method .toString() returns information about this class attributes as a String o and the methods coming from the interface Table Member getAttribute(int n) getAttributes() .getAttributeName(int n) getAttributeNames() Height o it is a class (or type) which is used in Football Player defining the type of the attribute height o it has two attributes int feet; int inches 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