Java Reference
In-Depth Information
Lab 16.1: Using Streams
The purpose of this lab is for you to become familiar with reading from a
file and chaining streams.
1.
Suppose that you are given a file in the following format that repre-
sents final scores of football games:
Dallas Cowboys
21
San Francisco 49ers
30
Denver Broncos
34
Oakland Raiders
0
For example, the Cowboys lost to the 49ers 30 to 21, and the Broncos
beat the Raiders 34 to 0. The home team is listed first, followed by
their score, and then the visiting team and their score are listed.
Locate the file scores.txt in the lab solutions and copy it to the direc-
tory in which you are working.
2. Write a program that reads in all of the scores in the file and dis-
plays them in the following format at the console output:
Home: Dallas Cowboys 21
Visitor: San Francisco 49ers 30*
Place an asterisk next to the winning score.
Run the program reading the file scores.txt, and you should see the
output of seven football games.
Lab 16.2: Using Logging
In this lab, you modify your game from Lab 15.2 so that it keeps track of
the winners of the race in a file and uses logging.
1. Within the main() method of the Race class from Lab 15.2, output
the winner of the race in a file named winners.dat. Be sure to
append the winner at the end of the file. Use whichever output
streams or writer classes that you feel are appropriate.
2. In addition to saving the winner to a file, generate a logging mes-
sage of level INFO that states that the race has been won and also
Search WWH ::




Custom Search