Different shells has been provided for you to fill in. You must start implementi
ID: 3853266 • Letter: D
Question
Different shells has been provided for you to fill in. You must start implementing the files in the following order:
1. Team class
2. TeamNode
3. shellLinkList
4. TeamLinkList
5. TeamLinkListClient
The code for some of the methods has been provided for you.
Problem: Code a class encapsulating a singly link list of football teams. A football team has the following attributes:
1.Team’s nickname
2.Its number of wins
3. Its number of losses ( assumed there are no tie games)
Implement the following methods:
1. Constructor
2. Insert
3. Delete
4. Peek
5. toString: returns a string containing the info about all the teams
6. mostWins: this method returns the team with the most wins
7. bestFive: this method returns the top five teams based on the winning percentage. If multiple teams have the same winning percentage, just return the first five teams
8. Search: this method search the list for a particular team and returns the information for the team. If the team is not in the list it should return null.
9. Count: this method returns the number of the teams in the list.
10. isEmpty: returns true if the list is not empty, and returns false otherwise.
Write a driver class that does the following:
1. creates an object of the list
2. write a method called populate that populate the list by reading from a file that you need to create
3. Write a method that accepts the name of the team and the list of all the teams as its parameter, and then call the method delete to delete that team from the list.
4. Write a method called first team that accepts the list of the team as its parameter and returns the first team in the list.
5. Write a method call insert that accepts the list of the team as its parameter. This method asks for a team information, then adds the team to the list.
6. Read the following information for each team from a file and create the link list by calling appropriate methods.
Number of items in the list: 10
nickname: Browns # of wins: 3 # of losses:13
nickname: Cowboys # of wins: 14 # of losses: 2
nickname: Patriots # of wins: 14 # of losses: 2
nickname: Raiders # of wins: 6 # of losses: 10
nickname: Falcons # of wins: 5 # of losses: 11
nickname: Eagles # of wins: 12 # of losses: 4
nickname: Giants # of wins: 7 # of losses: 9
nickname: FortyNiners # of wins: 8 # of losses: 8
nickname: Ravens # of wins: 11# of losses: 5
nickname: Redskins # of wins: 10 # of losses: 6
Explanation / Answer
public DataStructureException( String s ) { super( s ); } } public abstract class ShellLinkedList { protected TeamNode head; protected int numberOfItems; //set the head to null //set the numberOfItems to 0 public ShellLinkedList( ) { //set the head to null //set the numberOfItems to 0 } public int getNumberOfItems( ) { return 0; } public boolean isEmpty( ) { // return the number of the items in the list return false; } public String toString( ) { //returns a string representing all the items in the list return ""; } } public class Team { private String nickname; private int wins; private int losses; /** constructor * @param newNickname starting value for nickname * @param newWins starting balue for wins * @param newLosses starting value for losses */ public Team( String newNickname, int newWins, int newLosses ) { } /** getNickname * @return nickname */ public String getNickname( ) { return ""; } /** getWins * @return wins */ public int getWins( ) { return 0; } /** getLosses * @return losses */ public int getLosses( ) { return 0; } /** setNickname * @param newNickname new value for nickname */ public void setNickname( String newNickname ) { } /** setWins * @param newWins new value for wins * newWins must be >= 0. otherwise value is unchanged */ public void setWins( int newWins ) { } /** setLosses * @param newLosses new value for losses * newLosses must be >= 0. otherwise value is unchanged */ public void setLosses( int newLosses ) { } /** equals * @param o another Team object * @return true if the instance variables in this object are equal to the * instance variables in t; false otherwise */ public boolean equals( Object o ) { return false; } /** toString * @return String representation of nickname, wins, and losses */ public String toString( ) { return ""; } /** winningPercentage * @return wins / total games; 0 if no games have been played */ public double winningPercentage( ) { return 0; } } import java.util.ArrayList; public class TeamLinkedList extends ShellLinkedList { // head and numberOfItems are inherited instance variables public TeamLinkedList( ) { super( ); } /** insert method * @param t Team object to insert */ public void insert( Team t ) { // create a TeamNode object and store it in tn //call the method setNext on the object tn with the parameter head //set the head to tn //increment numberOfItems } /** delete method * @param searchNickname nickname of Team to delete * @return the Team deleted */ public Team delete( String searchNickname ) throws DataStructureException { //make a copy of the head node called current //create an objcet of TeamNode called previous and set it to null TeamNode current = head; TeamNode previous = null; //as longas current is not null and the name of the team is not the name of the team of the current node { //set previous to current //set the current to current.next } if ( current == null ) // not found throw new DataStructureException( searchNickname + " not found: cannot be deleted" ); // else { // if current is equloa to the head nodes //delete the head node // delete head and adjust the new head // else //delete the node at the location and adjust the refrence addresees numberOfItems--; return current.getTeam( ); } } /** orderTeams method * @return an ArrayList of the teams ordered in descending order by winning percentages */ public ArrayList orderTeams( ) { ArrayList list = new ArrayList( ); // Fill list with the linked list of teams TeamNode current = head; while ( current != null ) { list.add( current.getTeam( ) ); current = current.getNext( ); } ArrayList orderedList = new ArrayList( ); // fill orderedList from list using a modified version of selection sort // sorting in descending order by winning percentages double currentMaxWinPercentage = 0; Team temp, tempMaxWP; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.