Page 1 of 1

Question TableData public void loadTable(); public ArrayList getTable(); public ArrayList getHeaders(); public ArrayList

Posted: Fri Jul 08, 2022 7:27 am
by answerhappygod
Question TableData public void loadTable(); public ArrayListgetTable(); public ArrayList getHeaders(); public ArrayListgetLine(int line); public ArrayList> getLines(int firstLine, intlastLine); limplements FootbalIPlayerData ArrayList players; voidReadPlayersFromXML() public void loadTable( public ArrayListgetTable() ..) public ArrayList getHeaders()...) public ArrayListgetLine(int line) ...) public ArrayList ArrayList>getLines(intfirstLine, int lastLine) ..) FootballPlayerData will implement theinterface TableData writing real code for all the abstract methods.Person TableMember * String name . Height height public StringgetAttribute(int n); public ArrayList getAttributes(); int weight .String hometown String highSchool public StringgetAttributeName(int n); public ArrayList getAttributeNames(); .String toString() extends implements FootballPlayer Height int feetint inches int number String position String toString( ) [...)public String getAttribute(int n){...^ public ArrayListgetAttributes() (...) public String getAttributeName(int n) {...^public ArrayList getAttributeNames() ...) . String toString()FootballPlayer will implement the interface TableMember writingreal code for all the abstract methods. app Model model -newModel(); Model public Model() FootballPlayerData fpData - newFootballPlayerData(); System.out.println(System.out.println(fpData.getHeaders().toString()),;System.out.println(fpData.getHeaders().toString()); //yes, we arerunning this twice for testing purposes System.out.println(System.out.println(fpData.getLine(4).toString());System.out.println(fpData.getLine(4).toString()); //yes, we arerunning this twice for testing purpose:s System.out.println(System.out.println(fpData.getLine(50).toString());System.out.println(fpData.getLine(123).toString());System.out.println( ArrayList> lines = fpData.getLines(0, 4):for (int i = 0; i 〈 lines.size(); i++) System.out.println(i+ - +lines.get(i).toString()); System.out.println( Model is used to testif the TableData interface was implemented correctly byFootballPlayerData. the interfaces TableMember TableData Model.javawhich is ready to test your project when you have all the classesdeveloped FootballPlayerData.java you will keep developingFootballPlayerData as described below. This is the most importantpart of this assignment The method ReadPlayersFromXML( ) requiresthat the classes it uses (FootballPlayer, Height, and Person) havean empty constructor (besides the "regular" constructor you areusing have all getters and setters (and you should already if youare using the required encapsulation) FootballPlayer.java (shouldbe implementing TableMember) with an extra empty constructor, itneeds to be explicitly declared "public" all the attributes have tohave the exact same names as described in the assignment all theattributes have to have getters and setters Height.java with anextra empty constructor, it needs to be explicitly declared"public" all the attributes have to have the exact same names asdescribed in the assignment all the attributes have to have gettersand setters Person.java with an extra empty constructor, it needsto be explicitly declared "public" all the attributes have to havethe exact same names as described in the assignment all theattributes have to have getters and setters App.java Controller(not being used in this lab) Model FootballPlayer.javaFootballPlayerData.java Height.java Model.java Person.javaTableData.java TableMember.java View (not being used in this lab)NetBeans File Edit View Nav ProjectS Files ServicesA03B_Solution_FootballPlayerTable Source Packages App.javaController Model FootballPlayer.javia FootballPlayerData.javaHeight.java Model.java Person.java TableData.java Table Member·javaView Test Packages Libraries Test Libraries Functionality Theapplication App creates a Model object The Model class creates oneFootballPlayer object displays information to test the newlyimplemented methods The classes App it has the main method which isthe method that Java looks for and runs to start any application itcreates an object (an instance) of the Model class Model has tohave the code below package Model; import java.util.ArrayList;public class Model { public Model() { FootballPlayerData fpData =new FootballPlayerData();System.out.println("=============================================================");System.out.println(fpData.getHeaders().toString());System.out.println(fpData.getHeaders().toString()); //yes, we arerunning this twice for testing purposesSystem.out.println("=============================================================");System.out.println(fpData.getLine(4).toString());System.out.println(fpData.getLine(4).toString()); //yes, we arerunning this twice for testing purposesSystem.out.println("=============================================================");System.out.println(fpData.getLine(50).toString());System.out.println(fpData.getLine(123).toString());System.out.println("=============================================================");ArrayList> lines = fpData.getLines(0, 4); for (int i = 0; i <lines.size(); i++) { System.out.println(i+" - "+lines.get(i).toString()); }System.out.println("=============================================================");} } sample output of running Model.java Output -A03B_Solution_FootballPlayerTableData_19 (run) run: [number,position, name, height, weight, hometown, highSchool] [number,position, name, height, weight, hometown, highSchool] [26, RB,Saquon Barkley, 511, 222, Coplay, Pa., Whitehall] [26, RB, SaquonBarkley, 511, 222, Coplay, Pa., Whitehall] [32, LB, Jack Haffner,510, 218, State College, Pa., State College Area] [98, DT, AnthonyZettel, 64, 284, West Branch, Mich., Ogemaw Heights] 0 [2, S,Marcus Allen, 62, 209, Upper Marlboro, Md., Dr. Henry A. Wise, Jr.]1 - [37, CB, Kyle Alston, 59, 180, Robbinsville, N.J.,Robbinsville] 2 - [28, S, Troy Apke, 61, 198, Mt. Lebanon, Pa.,Mount Lebanon] 3 - [35, LB, Matthew Baney, 60, 225, State College,Pa., State College] 4 - [26, RB, Saquon Barkley, 511, 222, Coplay,Pa., Whitehall] BUILD SUCCESSFUL (total time: 0 seconds) it createsa FootballPlayerData object uses this object to test and displaythe result of the newly implemented methods getHeaders( )getLine(int n) getLines( int firstLine, int lastLine) Person hasthe following attributes String name; Height height; int weight;String hometown; String highSchool; and a method String toString( )toString( ) overrides the superclass Object toString( ) methodtoString( ) returns information about this class attributes as aString encapsulation if you want other classes in the same packageyo have access to the attributes, you need to make them protectedinstead of private. see more about encapsulation here.FootballPlayer has the following attributes int number; Stringposition; has the following method from the previous lab StringtoString( ) toString( ) overrides the superclass Object toString( )method toString( ) returns information about this class attributesas a String and the methods coming from the interface TableMembergetAttribute(int n ) getAttributes( ) getAttributeName(int n)getAttributeNames( ) Height it is a class (or type) which is usedin FootballPlayer defining the type of the attribute height it hastwo attributes int feet; int inches and a method String toString( )toString( ) overrides the superclass Object toString( ) methodtoString( ) returns information about this class attributes as aString it returns a formatted string with feet and inches forinstance: 5'2" FootballPlayerData you need to start with this codepackage Model; import java.beans.XMLDecoder; importjava.io.BufferedInputStream; import java.io.FileInputStream; importjava.util.ArrayList; public class FootballPlayerData privateArrayList players; public FootballPlayerData() players newArrayList<>) public void ReadPlayersFromXML) tryFootballPlayer fp; XMLDecoder decoder; decoder = new XMLDecoder(newBufferedInputStream(new FileinputStream(FootbalÏPlayerTable.xmL))); fp - new FootballPlayer); while (fp !- null) try fp -(FootballPlayer) decoder. read0bject); players.add(fp); + catch(ArrayIndexOutOfBoundsException theend) //System.out.println(end offile) break; decoder.close(); catch (Exception xx)txx.printStackTrace(); has the following attribute ArrayListplayers; this is the array with all the FootballPlayer objects andthe methods coming from the interface Data (these are the methodsyou need to implement and write the full code for) public voidloadTable(); public ArrayList getTable(); public ArrayListgetHeaders(); public ArrayList getLine(int line); publicArrayList> getLines(int firstLine, int lastLine); and a methodto read the FootballPlayer objects from a XML and load theArrayList players public void ReadPlayersFromXML( ) this methodwill be used in loadTable( ) the method is ready and available inthe FootballPlayerData starter file The Interface TableData it isan interface remember the interface definition Interfaces are oftencompared to a contract, to a promise to implement the methodsdescribed in the interface. An interface in Java does not have anyreal code for implementation of its methods, it has only theskeleton of the methods. When a class decides to implement aninterface, it has to contain the real code for each method in theinterface. These are the five methods that FootballPlayerData hasto implementf public void loadTable(); It needs to be called in theconstructor to make the table ready and available right away. Itloads real data into the array list. The FootballPlayerData starterclass has a method that help with this task. The methodReadPlayersFromXML( ) read the FootballPlayer objects from an XMLfile and load them into the players ArrayList. public ArrayListgetTable(); Returns the full table of data. Although right now isnot required, soon you will need this method to return a specificArrayList instead of a generic ArrayList. public ArrayListgetHeaders(); The method will return an ArrayList of Strings withthe names of the FootballPlayer fields (the "headers"). publicArrayList getLine(int line); The method will return an ArrayList ofStrings with the values of the FootballPlayer object in a chosenline "n" in the table. public ArrayList> getLines(int firstLine,int lastLine); This methods used the getLine( ) method. It gets aset of lines (each one of them an array of Strings) from getLine(int n) and adds them to an array of arrays. It returns this arrayof arrays. A strategy In the same you you did in the lastassignment, here already developed methods can help you in writingnew methods. getLine(int line) can use FootballPlayergetAttributes( ) getHeaders( ) can use FootballPlayergetAttributeNames( ) getLines(int firstLine, int lastLine) can useFootballPlayerData
Question
implement the interface TableData in FootballPlayerData