Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The use of the class name here tells the computer which class to look in to find the method. It also lets you distinguish between


The use of the class name here tells the computer which class to look in to find the method. It also lets you distinguish between Poker.playGame() and other potential playGame() methods defined in other classes, such as Roulette.playGame() or Blackjack.playGame(). More generally, a subroutine call statement for a static subroutine takes the form hsubroutine-namei(hparameters i); if the subroutine that is being called is in the same class, or hclass-namei.hsubroutine-namei(hparametersi); if the subroutine is defined elsewhere, in a different class. (Non-static methods belong to objects rather than classes, and they are called using object names instead of class names. More on that later.) Note that the parameter list can be empty, as in the play

Start with an outline of the algorithm and apply stepwise refinement. Here is a short pseudocode algorithm for a guessing game program: Pick a random number while the game is not over: Get the user's guess Tell the user whether the guess is high, low, or correct. The test for whether the game is over is complicated, since the game ends if either the user makes a correct guess or the number of guesses is six. As in many cases, the easiest thing to do is to use a "while (true)" loop and use break to end the loop whenever we find a reason to do so. Also, if we are going to end the game after six guesses, we'll have to keep track of the number of guesses that the user has made. Filling out the algorithm gives: Let computersNumber be a random number between 1 and 100 Let guessCount = 0 while (true): Get the user's guess Count the guess by adding 1 to guess count if the user's guess equals computersNumber: Tell the user he won break out of the loop if the number of guesses is 6: Tell the user he lost break out of the loop if the user's guess is less than computersNumber:

image

public void removeCard (Card c) { // If the specified card is in the hand, it is removed. public void removeCard (int position) { // Remove the card in the specified position from the // hand. Cards are numbered counting from zero. If // the specified position does not exist, then an // exception is thrown. public int getCardCount () { // Return the number of cards in the hand. public Card getCard (int position) { // Get the card from the hand in given position, where // positions are numbered starting from 0. If the // specified position is not the position number of // a card in the hand, an exception is thrown. public void sortBySuit () { // Sorts the cards in the hand so that cards of the same // suit are grouped together, and within a suit the cards // are sorted by value. Note that aces are considered // to have the lowest value, 1. public void sortByValue () { // Sorts the cards in the hand so that cards are sorted into // order of increasing value. Cards with the same value // are sorted by suit. Note that aces are considered // to have the lowest value.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is the stepwise refinement of the algorithm for a guessing game program Pick a random number between 1 and 100 This can be done using a random number generator function that is available in most ... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions