Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that computes the scores for two players, and determine who, if anyone, wins a game of darts. Darts are thrown at

Write a Java program that computes the scores for two players, and determine who, if anyone, wins a game of darts. 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:

image text in transcribed

Ring radii are at 3", 6", 9", 12" and 15" (the Bullseye has a diameter of 6"). A game of simple darts between two players is played as follows. The first player throws 3 darts at the board. A score is computed by adding up the point values of each region that a dart lands in. The darts are removed. The second player throws 3 darts at the board; the score for player two is computed the same way as it is for player one. The player with the higher score wins. If a dart lands exactly on a ring (region boundary), the higher point value is awarded. Any dart outside the outer ring receives no points. For the purposes of this problem, you can assume that a dart has an infinitely fine point and cannot land partially on a ring; it is either on the ring or it is not on the ring.

Input will be from a file with the first line determining the number of datasets in the file. A dataset is a line with 12 double values separated by spaces. Each pair of values represents the X and Y distances respectively of a dart from the center of the board in inches. The center is located at X = 0, Y = 0. The range of values are: -20.0

SCORE: N to M, PLAYER P WINS.

or:

SCORE: N to M, TIE.

N is player ones score, and M is player twos score. P is either 1 or 2 depending on which player wins. All values are non-negative integers. Let the user input the file name from the keyboard. Refer to the sample output below.

Sample File:

2

-9 0 0 4.5 2 2 9 0 0 4.5 2 2

-19.0 19.0 0 0 0 0 3 3 6 6 12 12

Sample Run:

Enter the data file: darts.txt

SCORE: 240 to 240, TIE.

SCORE: 200 to 140, PLAYER 1 WINS

20 40 60 80 100 80 60 40 20 20 40 60 80 100 80 60 40 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions