Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java The game of sticks begins with a pile of sticks. On each turn the player may select to pick up 1 to 3

in java

image text in transcribed

image text in transcribed

image text in transcribed

The game of sticks begins with a pile of sticks. On each turn the player may select to pick up 1 to 3 sticks. Whoever picks up the last stick is the loser You will implement the Sticks Game application. To do this you will create a SticksGame class and a SticksGameApp class. The SticksGameApp class will contain main method requiered for the running the game interations with the players. You will need to implement the four parts of the class. Name: SticksGame SticksGame -initialNumOrsticks int -numOfticks Instance variables There are three attributes to keep track of: intial NumOfSticks - an integer that keeps track of sticks the game started with. . numOfSticks - an integer that keeps track of the current number of sticks in the pile. getNumSticks): int getcurrentPlayerD: int getPled:String +isOvert) boclean currentPlayer an integer that keeps track of which player's turn it is getwinner): int + reset) void + pickUpStickslint) : void Constructors Implement two constructors: The first constructor takes in no input parameters and creates a game starting with 20 sticks. The second constructor takes in an integer value as in input parameter and creates a game starting with the inputted number of sticks. Class Methods: Implement the following class methods: .getNumSticks - takes no input parameters and returns the number of sticks left as an integer. . getCurrentPlayer - takes no input parameters and returns the current player as an integer .getPile -takes no input parameters and returns a String representation of the pile. (.e. I11. .isOver- takes no input parameters and returns a boolean value if the game is over or not . getlWinner - takes no input parameters and returns the winning player as an integer (you can return O if there is no winner) . reset takes no input parameters and resets the game to the initial number of sticks and player 1's turn. pickUpSticks - takes in an integer of how many sticks should be removed from the pile For now don't worry about data validation. If the user enters something that is not a valid number, just treat is at a 1. Example Runs It's time for an exciting game of Sticks! How many sticks would you like to start with? Player 1 there are 5 stick(s) left. How many do you want to take (1-3): 1 Player 2 there are 4 stick (s) left. How many do you want to take (1-3) 3 Player 1 there are 1 stick(s) left. How many do you want to take (1-3): 1 Player 2 wins! That was exciting, would you like to play again

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions