辅导CISC124、讲解NHL Simulator Tool Java

- 首页 >> Java编程


CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 1

Aim – To implement a simulation of an ice hockey season in one of the divisions of the NHL

(National Hockey League) that would potentially allow a given team to estimate its chances of

making it to the playoffs. The simulation will run as a text-based, interactive, and menudriven

program that will comply with a set of rules as specified below.

The objectives in this assignment are multiple. First, to build a small prototype of a data analysis

tool, using as input artificial data generated as pseudo-random numbers, which could

eventually grow to a robust hockey player performance evaluation tool using real NHL

statistical data. Second, to give you practice designing and coding simple classes and methods

using loops, conditionals and console I/O in the Java language. Third, to give you an initial

exposure to object-oriented techniques to solve computational problems.

To attain the goals of this prototype, you will write the following Java classes:

1) A class Player to keep track of identification and performance attributes for a hockey

player.

2) A class Team to maintain hockey player configurations and team results.

3) A class Game to simulate and capture the results of a hockey game.

4) A main driver class NHLSimulator that will be able to simulate the results of each and all

the ice hockey games scheduled for an NHL hockey season and conference, respond to

inquiries about individual players, handle the interactions with the user of the

simulation via a text-based interactive menu, and display on the user’s console a

formatted report according to a given specification.

General Description

As a software developer, working for the administration office of the Toronto Maple Leafs ice

hockey team, you have been tasked to write a Java program that would simulate the results of

hockey games based on a random, range-limited estimation of the skill level of the players

involved in them. Executive management at this hockey club wants to have this simulation tool

to estimate how well the current player roster would fare against other teams in its own

conference. They would like to know whether the team has a good chance of making it to the

playoffs this year. To meet this goal, the team needs to finish the regular season in at least the

8

th position in its conference.

An annual NHL season is played in two conferences: Eastern and Western, each one having 16

(see Table 1, Appendix A) and 15 teams, respectively. Your program will simulate game results

between Eastern conference teams only, that is, interconference games are not included.

Therefore, the final tallying of results and team positions in the Eastern conference will be

based only on the games specified above.

During a regular hockey season, every Eastern conference team plays two games against every

other team in the same conference, one as a visitor and one as a host. If at the end of

regulation time, both times are tied (have scored the same number of goals), the game goes to

overtime. For simplicity, we will consider that each game ends in regulation time or in overtime

(i.e., no shootouts). The first team to score a goal in overtime wins the game. The game’ s

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 2

winning team gets 2 points, and the losing team gets 0 points if the game ended in regulation

time, 1 point if it ended in overtime.

For the simulation, we will consider that each team has 13 forwards, 8 defensemen and 4

goalies, for a total of 25 players. Each player has a skill level (i.e., ability to play the game)

represented by integers, between 1 (lowest) and 10 (highest). The skill levels for the Toronto

Maple Leafs players are shown in Table 1, Appendix A (along with their player numbers and

types (forward, defense or goalie).

The program will randomly generate the skill levels for the players in the other remaining 15

teams, using the skill level ranges provided in Table 2, Appendix A. For example, Boston’s

forwards will get a randomly-assigned skill level between 5 and 9, defensemen will get an

integer between 4 and 9, and goalies an integer between 5 and 7. This same logic applies for all

the remaining teams in Table 2, Appendix A. The program will randomly assign to each player a

unique integer identifier between 1 and 99. It will name the player as Fn (forwards), or Dn

(defensemen), or Gn (goalies), where n is the identifier assigned to the player. It will also decide

whether a player is a forward, defenseman or goalie, respecting the quotas defined for each

player type (i.e., 13 forwards, 8 defensemen, 4 goalies).

To simulate the outcome of a game involving two teams (let’s say teams 1 and 2), your program

will apply the following rules:

1. Add up the skill level of all the forwards and defensemen in each of the two teams. Let

us call these totals P1 and P2.

2. Randomly select one of the 4 goalies in each team. Let us call the skill levels of the

goalies selected from teams 1 and 2 “G1” and “G2”, respectively.

3. Compute the total skill levels for teams 1 and 2 as: T1 = P1 + G1 and T2 = P2 +G2,

respectively.

4. For each of the two teams, randomly decide whether its forwards, defensemen and

goalie will play well, poorly, or at their initially-specified skill level in the current game.

5. If the forwards play well, add 25 points to the team’s total skill level (i.e., T1 = T1 + 25, or

T2 = T2 + 25). If they play poorly, subtract 25 points from the team’s total skill level (i.e.,

T1 = T1 - 25, or T2 = T2 - 25). If they play at their initially-specified skill level, do not

change T1 (or T2). Similarly, in the case of defense players, add or subtract 40 points. In

the case of the goalie, add or subtract 60 points.

6. During regulation time, each team will randomly score 0, 1 or 2 goals for each 50 points

computed in its total skill level computed for the current game (i.e., T1 and T2). It will

score 0 or 1 goals for a remainder fraction of 50 points.

7. During overtime, each team will randomly select 3 players among forwards and

defensemen and will randomly select one of the four goalies. The total skill level for all

the 4 players will be computed in each team. The team whose total skill level, computed

in this manner, is greater, will be the first to score one goal in overtime (and terminate

the game). If both totals are equal, your program will randomly decide which team

scored the first overtime goal.

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 3

Program Implementation Requirements

I – User Interface and Program Flow

Upon starting, the program will display on the console the following menu:

NHL Simulator (Version 0.1). Author: [Your first and last name]

1 – Simulate NHL Season (Eastern Conference)

2 – View Team Skill Level Profile

3 – Display End of Regular Season Table

Select Option [1, 2 or 3] (9 to Quit):

Upon completing the processing of any of the operations 1, 2, or 3, your program will return to

display the previous menu and wait for the user to select a menu option. If the user enters 9,

the program terminates.

a) Simulate NHL Season (Eastern Conference) – Selecting this option will run a simulation of all

the 240 games in the Eastern Conference for the current regular season, using the algorithm

described in the “General Description” section. After completing the simulation, your program

will display the teams with the most and least points at the end of the regular season, as

follows:

NHL Regular Season – Eastern Conference – 2018/2019

First Team: [Team Name] Points: [# of Points]

Last Team: [Team Name] Points: [# of Points]

Simulation completed!

Afterwards, the program will return to the main menu.

b) View Team Skill Level Profile – Selecting this option will display the prompt:

Enter Team Name:

The user must enter one of the names listed in Table 2, Appendix A. If the name is invalid, the

program must display:

[Entered name] is invalid! Please re-enter or press [Enter]

If the user just pressed [Enter] and no team name, then the program returns to the main menu.

Otherwise, it displays:

Enter Team Name:

If the team name is valid, the program displays skill level data for all the players in the team

requested, using the following format, and returns back to the main menu:

No Name Position Skill Level

*** ****************** ********** ********

34 F34 Forward 8

Etc.

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 4

If the user selects this option without first running option 1: Simulate NHL Season (Eastern

Conference), the program displays the following error message and returns to the main menu:

Must run NHL Eastern Conference Simulation before accessing this option!

c) Display End of Regular Season Table – Selecting this option will display the Total Scores and

Statistics Report for the Eastern Conference, as of the end of the 2018/2019 regular season.

The program lists the teams in alphabetical order (as shown in Table2, Appendix A), using the

format shown below, and returns to the main menu.

TOTAL SCORES AND STATISTICS REPORT

Team Name GP W L OTL Pts GF GA Diff

Boston 30 18 10 2 38 83 71 +12

Buffalo 30 9 18 3 21 51 85 -44

Etc.

After displaying the report, the program will issue the prompt: Press any key to continue;

thereafter, it will return to and display the selection menu.

If the user selects this option without first running option 1: Simulate NHL Season (Eastern

Conference), the program displays the following error message and returns to the main menu:

Must run NHL Eastern Conference Simulation before accessing this option!

II – Testing

Produce a trace file named runlog.txt, which contains the logging of all the user interaction and

output displayed on the console for the menu selections explained in section I, points a), b) and

c). (Note: runlog.txt should include the output produced in “Total Scores and Statistics Report”).

III – Analysis

1) According to your run of the simulation, did the Toronto Maple Leafs make it to the

playoffs?

2) If they didn’t, what do you think would be the minimum skill level required by the

defensemen and goalies in order to make it to the playoffs?

3) If they did, what do you think would be the minimum skill level required by the

defensemen and goalies in order to end the regular season in first place?

Provide your answers in a text file named answers.txt.

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 5

III – Submission

Compress the source code for classes NHLSimulator, Team, Player and Game, as well as files

runlog.txt and answers.txt, into a single zip archive file named:

[your student number]_Assignment1.zip

For example, if your student number is 12345678 then you will name your submission file as

12345678_Assignment1.zip

Submit file [your student number]_Assignment1.zip via onQ by January 30, 2018, 11:00 p.m.

IV – Marking Scheme

Implementation of class NHLSimulator 3 points

Implementation of class Player 3 points

Implementation of class Team 3 points

Implementation of class Game 3 points

Generation of runlog.txt trace file 4 points

Answers provided in answers.txt file 2 points

Code style and documentation 2 points

________

TOTAL: 20 points

V – Additional Guidelines for this Assignment

Your program should use good indentation and white space, good variable names and some

internal comments explaining what the code is doing. One comment at the top of the

program should contain at least your name, your NetID, date, and an overall description of

what your program does (3 to 4 lines).

Use the Random class, in the java.util package, to create a random number generation

object seeded with an arbitrary number. For example, the following code accomplishes this:

static Random generator = new Random(System.currentTimeMillis());

System.currentTimeMillis() returns the current time in milliseconds, so it will yield a different

seed value every time you run your program. You need to call the nextInt() method (see

details in the Java API documentation) in the generator object to obtain a new random

integer. This object could be assigned to an attribute of class NHLSimulator.

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 6

Appendix A

Table 1: Toronto Maple Leafs Roster

No. Name Position Skill Level

28 C. Brown forward 5

63 T. Ennis forward 4

33 F. Gauthier forward 5

11 Z. Hyman forward 7

18 A. Johnsson forward 7

43 N. Kadri forward 7

24 K. Kapanen forward 8

26 P. Lindholm forward 8

12 P. Marleau forward 8

16 M. Marner forward 9

34 A. Matthews forward 9

29 W. Nylander forward 9

91 J. Tavares forward 10

23 T. Dermott defenseman 8

51 J. Gardiner defenseman 4

2 R. Hainsey defenseman 5

3 J. Holl defenseman 6

52 M. Marincin defenseman 4

92 I. Ozhiganov defenseman 6

44 M. Rielly defenseman 9

22 N. Zaitsev defenseman 8

31 F. Andersen goalie 10

30 M. Hutchinson goalie 7

50 K. Kaskisuo goalie 5

40 G. Sparks goalie 6

CISC124 – Winter 2019

Lab Assignment 1: NHL Simulator Tool

Page 7

Table 2: Teams in the Eastern Conference

No Team Forwards

Skill Level Range

Defensmen

Skill Level Range

Goalies

Skill Level Range

1 Boston 5 – 9 4 – 9 5 – 7

2 Buffalo 6 – 9 4 – 7 4 – 7

3 Carolina 4 – 8 5 – 7 4 – 9

4 Columbus 4 – 9 5 – 8 7 – 10

5 Detroit 4 – 7 6 – 8 4 – 6

6 Florida 5 – 7 4 – 8 5 – 9

7 Montréal 4 – 7 4 – 7 4 – 9

8 New Jersey 4 – 7 4 – 7 5 – 6

9 NY Islanders 6 – 8 5 – 7 6 – 8

10 NY Rangers 5 – 7 4 – 6 5 – 7

11 Ottawa 4 – 6 4 – 5 4 – 5

12 Philadelphia 4 – 6 4 – 6 4 – 7

13 Pittsburgh 6 – 10 4 – 7 5 – 7

14 Tampa Bay 6 – 10 6 – 10 7 – 9

15 Washington 6 – 10 5 – 8 6 – 8


站长地图