Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer correctly with explanation JAVA I need help writing Java code for this method public void throwDart(ThrowType type, int number) which simulates the action

Please answer correctly with explanation

JAVA

I need help writing Java code for this method "public void throwDart(ThrowType type, int number)" which simulates the action of the current player throwing one dart, adjusting the points as needed, and adjusts the players dart count. Switches to the other player if the current player uses up all darts or busts; does not switch to the other player if the current player wins. Does nothing if the game is already over. The number parameter is ignored in the case of type MISS, OUTER_BULLSEYE, or INNER_BULLSEYE. Busts means : the players score goes negative, gets to 1, or gets to zero but not ona double or inner bullseye, the player has gone bust, and their score is reset to whatever it was at the beginning of their turn, and the turn ends even if they haven't thrown all their darts. Here are some test cases: g = new DartGame(1, 100, 3); g.throwDart(DOUBLE, 10); System.out.println(g); g.throwDart(DOUBLE, 10); System.out.println(g); g.throwDart(DOUBLE, 10); System.out.println(g); g.throwDart(DOUBLE, 10); System.out.println(g); System.out.println(); // Expected: // Player 0: 100 Player 1: 80 Current: Player 1 Darts: 2 // Player 0: 100 Player 1: 60 Current: Player 1 Darts: 1 // Player 0: 100 Player 1: 40 Current: Player 0 Darts: 3 // Player 0: 80 Player 1: 40 Current: Player 0 Darts: 2

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

Step: 3

blur-text-image

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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions