The use of the class name here tells the computer which class to look in to find
Question:
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:
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill