CSE-1020: Introduction to Computer Science I
York University
Lab Test Exam: Winners
21 January 2010
  Welcome to the Lab-test Environment

During the test, you will not be able to access your regular home directory, access, receive, or send e-mail, print, or access the Internet.

The lab tests are closed-book and no aids are allowed.

At the end of your test session, this machine will be converted back to a standard, unrestricted Prism Lab machine. At this time, any files written by you during the test, except those that have been submitted, will not be recoverable. Make sure you submit your code before the end of the test. (Instructions to submit your code are below). If you do not submit your work on time, you will receive a grade of zero. (There are no exceptions.)

Instructions

You have the lab period, 80 minutes, to complete this lab test. The computers will automatically shutdown at the end of the time, warning you several minutes in advance. No additional time will be provided, so you must submit your work prior to this; otherwise, there will be no way to recover it (it will be lost), and you will receive a grade of zero (no exceptions).

You are encouraged to submit often during the test. Note that newer submissions overwrite older ones.

Your program will be marked for good style, as well as for running correctly (producing correct output in the correct format).

Submitting Your Work

When you submit a file, you should include at the top of the file your name (surname, given name) and your Prism lab login. These should be placed in a comment so that the file will compile. Note that files which do not compile will receive a large penalty when marked, no matter how small the error that prevented compiling.

Submit the class Winners.java before the time deadline. Here is the command to submit your work:

% submit 1020d 1020d Winners.java

Further details regarding the submit command can also be obtained by typing man submit.

Once again, you are encouraged to submit regularly. Newer submissions simply overwrite older ones.

Unlike eCheck assignments, there is partial credit possible. If you are able to finish all aspects of the program (for example, say, input validation was requested but you did not do this), you should still submit it.

Useful APIs

Here are the common APIs that you may access:

 
  The Task

Write a Java application called Winners.java.

The result of a hockey game between two teams is given as one line of input. An example result for a hockey game is:

TOR BOS 1 3

The two team names are given first (with one or more spaces between the names), followed by one or more spaces, followed by the number of goals each team scored (with one or more spaces between the number of goals). In the example, TOR scored 1 goal and BOS scored 3 goals, so BOS won the game and TOR lost the game. You may assume that there is always a winner for each game (there are no games where the number of goals scored is the same for each team).

Your program should prompt the user to enter a sequence of hockey game results (one game per line of input) until the user types Ctrl-d.

After the user is done entering the results, your program should print the header (Game#...) as ahown. It should follow with a row for each winning team for each game. This should print the name of the winning team for each game (see the sample output below). The game number should be printed using a width of 3 spaces, followed by a period; this is followed by 6 spaces and then the name of the winning team.

Your program should also print all of the teams that played one or more games but who won none of them. (See the sample output below.)

Your program should deal with user input errors such as entering a non-integer for the number of goals scored and entering fewer than four items per line (see sample runs below). However, you may assume that there will always be at least one valid game result entered by the user.

Your output should look exactly like that indicated in the sample runs below.

Hints:

  • Input errors can easily be dealt with using exception handling to catch RuntimeException.
  • Do not type in all of the sample input; use cut and paste!
Sample Runs

Here are three sample runs of a correctly written program. Note that the text in red is text that the user types. (Text in bold and red, e.g., Ctrl-d, would be typed by the user but would not show up on the screen.) The text in black is what the program types. The '%' represents the prompt from the command-line window (shell).

% java Winners
Enter scores for each game (Ctrl-d to finish)
TOR MON  0 1
Ctrl-d

Game#     Winning Team
  1.      MON

Teams winning zero games:
TOR

%
% java Winners
Enter scores for each game (Ctrl-d to finish)
TOR MON 0 1
TOR BOS 1 2
MON   DET 3 2
BOS MON 8 3
   NYR TOR 2 0
CHI TOR 6 4
CHI MON 3 4
BOS  NYR 1    2
DET CHI 2 3
MON NYR 3 2
BOS DET 5  4
NYR DET 2 1
BOS  CHI 6 3
 NYR CHI 3 2
Ctrl-d

Game#     Winning Team
  1.      MON
  2.      BOS
  3.      MON
  4.      BOS
  5.      NYR
  6.      CHI
  7.      MON
  8.      NYR
  9.      CHI
 10.      MON
 11.      BOS
 12.      NYR
 13.      BOS
 14.      NYR

Teams winning zero games:
DET
TOR

%
% java Winners
Enter scores for each game (Ctrl-d to finish)
MON TOR 1 3
MON TOR one three
Bad score; please try again.
MON TOR 1
Bad score; please try again.
Ctrl-d

Game#     Winning Team
  1.      TOR

Teams winning zero games:
MON

%

Coding

You should use good programming practises as described in the textbook, and your code should conform to the style guide in the textbook. You should comment at least minimally, as by the guidelines.

You should not use any features of Java not covered in the course. There will be some deduction if you do.