Starting from:

$29.99

Data Structures and Algorithms - Assignment No. 2

This assignment is on the application of Unordered Lists. You will need the source codes for
Node.java, LinkedList.java and List.java discussed in the lectures. You will also need the text file
nhlstats.txt (this file is given along with the link to this assignment).
Before you begin this assignment, it will be useful to study the Expense.java, ExpenseList.java
and ExpenseListDemo.java programs that were discussed in the lectures. You will also need
knowledge of File Processing and String Tokenizer.
You are given the raw scores of various NHL players’ regular hockey games in the file
nhlstats.txt. The file has data organized in the following manner:
Name Pos Team GP G A PIM SOG GWG
Marchand LW BOS 45 18 18 27 91 5
Eberle C EDM 48 16 21 16 133 3

etc.
Note: The first row is not there in the actual nhlstats.txt file. It just tells you what each
column stands for.
The meanings of abbreviations are as follows:
Pos stands for Position. In this column, C means Center, LW means Left Wing, RW means Right
Wing, LD means Left Defense, RD means Right Defense, and G means Goalie.
GP stands for Games Played.
G stands for Goals scored.
A stands for Assists.
PIM stands for Penalties In Minutes
SOG stands for Shots on Goal
GWG stands for Game Winning Goals.
So, for example, in the above file, Marchand plays Left Wing, belongs to team BOS (Boston
Bruins), played 45 games during the season, scored 18 goals, had 18 assists, spent 27 penalty
minutes, had 91 shots on goal and 5 game winning goals.
Now, from these numbers, hockey statisticians calculate interesting information, such as the
following:
• P (Points: this equals Goals plus Assists). For example, Marchand has 36 points and
Eberle has 37 points.
• PG (Points per Game: this equals P divided by GP). For example, Marchand’s PG is
36/45 = 0.80 and Eberle’s PG is 37/48 =0.77. (Caution: Integer division!)
• PCT (Shooting percentage: this equals goals divided by shots on goal multiplied by 100).
For example, Marchand’s PCT is (18/91)*100 = 19.8 and Eberle’s PCT is (16/133)*100
= 12.0. (Caution: Integer division!).Here is what your program should do. Follow these steps.
1. First create a class called PlayerRecord.java that has all the instance variables for one player
(Name, Position, Team, GP, G, A, PIM, SOG, GWG). Also include instance variables P, P/G, and
PCT for that player. Add the constructor and associated get, set and toString methods. Also add
the following methods:
a. Method that calculates the player’s P and sets that value
b. Method that calculates the player’s PG and sets that value
c. Method that calculates the player’s PCT and sets that value
Note: Use the DecimalFormat class to round off P/G and PCT to two decimal places.
public class PlayerRecord
{
….
}
Ca
public class NHLStats
{
private List<PlayerRecord playerlist;
……
}
In this class, include the following methods:
Constructor to create an empty list (of PlayerRecords)
add a PlayerRecord to the list
check if the list is empty
get the first item
get the next item
enumerate
Also add the following methods:
1. Who is the player with the highest points? : Method that displays the player’s name with
the maximum number of points and his team’s name. Note: If more than one player
has the largest number of points, display all the players and their teams.
2. Who is the most aggressive player? : Method that displays the name of the player who
had the maximum number of penalty minutes, his team name and his position. Same
note as in 1 applies.
3. Who is the most valuable player (MVP)? : Method that displays the name of the player
who scored the most number of game winning goals and his team’s name. Same note as
in 1 applies.
4. Who is the most promising player? : Method that displays the name of the player who
took the most number of shots on goal and their team names. Same note as in 1
applies.
5. Which team has the most penalty minutes? : Method that displays the name of the team
that had the most penalty minutes (sum of all penalty minutes of all players in that
team). Same note as in 1 applies.6. Which team has the most game winning goals? : Method that displays the name of the
team that had the most number of game winning goals (sum of all GWGs for that team).
Same note as in 1 applies.
7. Which team has the least game winning goals? : Method that displays the name of the
team that had the least number of game winning goals (sum of all GWGs for that team).
Same note as in 1 applies.
You may add other methods as needed.
Note: If you find it useful, you can create one more class called the Team class and store the
attributes of each team. This will help you search and get answers specific to a team.
3. Write a client program NHLListDemo.java with the main method that reads the file
nhlstats.txt and prints the following into another file nhlstatsoutput.txt.
Note: When you read data from the file, each line is read as a String. Use StringTokenizer to
break it down into individual components.
Note that the input file has rows in which the items are delimited by tabs. So you need to use
the StringTokenizer in a manner similar to the following:
token = new StringTokenizer(line, "\t");
Also to convert a String to an integer value, use Integer.parseInt(…).
Your output should be similar to the format given below:
NHL Results Summary
Name Position Team GP G A PIM SOG GWG P P/G PCT
Marchand LW BOS 45 18 18 27 91 5 36 0.80 19.8
Eberle C EDM 48 16 21 16 133 3 37 0.77 12.0
……
etc.
Players with highest points and their teams:

Most aggressive players, their teams and their positions:

Most valuable players and their teams:

Most promising players and their teams:

Teams that had the most number of penalty minutes:
….
Teams that had the most number of game winning goals:
….
Teams that had the least number of game winning goals:
….
Submit a zip file containing the following source codes:
PlayerRecord.java, NHLList.java, NHLListDemo.java, List.java, LinkedList.java, Node.java
and the output text file nhlstatsoutput.txt

More products