Due: Friday, 18 January 2007
A simple dartboard consists of a flat, circular piece of cork with concentric rings drawn on it. Darts are thrown at the board by players in an attempt to hit the center of the dartboard (the Bullseye). The region between each pair of rings (or the center and the first ring) represents a certain point value. The closer the region is to the center of the dartboard, the more points the region is worth, as shown in the diagram below:

Ring radii are at 3", 6", 9", 12" and 15" (the Bullseye has a diameter of 6"). A game of darts between two players is played as follows. Each player throws three darts. A score is computed by adding up the point values of each region that a dart lands in. The player with the higher score wins the game. If they have the same score, then the games ends in a tie.
You are to write a program that computes the scores for two players, and determine who, if anyone, wins the game. For the purposes of this problem, you can assume that a dart has an infinitely fine point. If a dart lands exactly on a ring boundary, the higher point value is awarded. Any dart outside the outer ring receives no points.
For each game G, print a line of the form:
or:
Game #G: N to M, player P wins.
where N is player one's score, and M is player two's score.
P is either 1 or 2 depending on which player wins.
All values are non-negative integers.
For the input:
Game #G: N to M, tie.
-9 0 0 -4.5 -2 2 9 0 0 4.5 2 -2 # Game 1 -19.0 19.0 0 0 0 0 3 3 6 6 12 12 # Game 2the output would be:
Game #1: 240 to 240, tie. Game #2: 200 to 140, player 1 wins.
java Bullseye < dataNow the characters found in the standard input come from the file named data. When the standard input comes from the keyboard a signal of some kind is needed to indicate from the interactive user when the end-of-file is reached because the length of the "file" cannot be known in advance. This signal is understood by the operating system which then passes it to the program. Different operating systems provide different mechanisms for doing this. In Unix the usual signal is typing control-D (in Dos, control-Z) on a line by itself. (Typing control-D in the middle of the line may have the effect of putting the u0004 character in the input stream instead of signaling end-of-file.)
The standard output is the stream of characters that the Java program writes to the PrintStream called System.out. The standard output is associated with the computer display by default, but can be associated with the file as in
java Bullseye > outputNow the output is collected in the file named output. Since keystrokes are echoed on the display, it is sometimes hard for the user to distinguish which characters on the display correspond to the standard input and which characters to the standard output. From the point of view of the program no such confusion exists.
Using standard input and standard output for IO is very flexible. The user of the program (instead of the program writer) can decide whether to type in the input or put the input in a some file. If the program was written to take input from a particular file, the user of the program has no choice.
final Scanner s = new Scanner (new BufferedInputStream (System.in));
for (;;) {
final String line = s.nextLine();
if (line==null) break; // null means end-of-file
System.out.println (line);
}
It will be necessary to include:
import java.util.Scanner; import java.io.BufferedInputStream;
Turn in the Java source code for the program using the submission server. The file name should be Bullseye.java and the project is proj02. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. For your convenience, here is a submission form for this assignment.
|
Course=cse4051 Project=proj02 |