// Stephen Gilbert // OCC - CS 170 // A guessing game for OOPJ chapter 5 import java.awt.*; import java.applet.*; import java.util.*; public class GOM extends Applet { // ------------------------------------------------------ // 1. Attributes // ------------------------------------------------------ // a. Top Panel components // b. Bottom Panel components // c. Center Panel components // d. Other attributes // COMPILE CHECK # 1 HERE // ------------------------------------------------------ // 2. Initialization // ------------------------------------------------------ public void init() { System.out.println("init() method called."); // a. Set the layout to border layout // b. Add components to the top of the applet // c. Add components to the south of the applet // d. Add some spacers to the east and west // e. Add the output to the Center // f. Call the newPlayer() method // COMPILE CHECK # 2 HERE } // ------------------------------------------------------ // 3. The newPlayer() Method // ------------------------------------------------------ private void newPlayer() { System.out.println("newPlayer() method called."); // a. Ask user to enter name and press ENTER // b. Disable all components except for thePlayer // c. Enable thePlayer, set it's text to "" // d. Set theGuess background to white // Set thePlayer background to yellow // Set focus on the player // COMPILE CHECK # 3 HERE } // ------------------------------------------------------ // 4. The action() Method // ------------------------------------------------------ public boolean action(Event ev, Object o) { System.out.println("action() method called."); // a. Handle the newPlayer Button // If the newPlayer button was pressed // Then call the newPlayer method // b. Handle thePlayer TextField // If thePlayer TextField generated the event // Then call the addPlayer() method // c. Handle the newNumber Button // If the newNumber button was pressed // Call the newGame() method // Enable theGuess component // Set focus to theGuess textfield // Set background color of theGuess to yellow // d. Handle theGuess TextField // If this TextField theGuess generated the event // Call the newGuess() method return true; // COMPILE CHECK # 4 HERE } // ------------------------------------------------------ // 5. The addPlayer() Method // ------------------------------------------------------ private void addPlayer() { System.out.println("addPlayer() method called."); // a. Retrieve text from thePlayer, store in playerName // b. Check to see if playerName is "" // If it is, then: // Print error message to theOutput // If not then: // 1. Set the amount remaining to 100 // 2. Set the number of games played to 0 // 3. Call the newGame() method // 4. Call the updateScore() method // 5. Disable thePlayer TextField. Set its // background color to white // 6. Enable all other components. // 7. Set focus to theGuess textfield // 8. Set background color of theGuess to yellow // COMPILE CHECK # 5 HERE } // ------------------------------------------------------ // 6. The newGame() Method // ------------------------------------------------------ private void newGame() { System.out.println("newGame() method called"); // a. Increment the number of games played [numGames] // b. Calculate a random number between 0 and 100 // Store the random number in the field theNumber // Use your Random object [randomizer] to generate // the number, using the instructions from class // c. Set the number of tries to 0 [numTries] // d. Call the displayInstructions() method // COMPILE CHECK # 6 HERE } // ------------------------------------------------------ // 7. The displayInstructions() Method // ------------------------------------------------------ private void displayInstructions() { System.out.println("displayInstructions() method called"); // a. Run the sample applet and read instructions // displayed on the screen after name is typed // b. Use the necessary TextArea methods to display // those instructions in the center of the screen // COMPILE CHECK # 7 HERE } // ------------------------------------------------------ // 8. The updateScore() Method // ------------------------------------------------------ private void updateScore() { System.out.println("updateScore() method called"); // a. Set the text in thePlayer textfield to the // player's name [playerName], along with the // the number of the current game [numGames] // b. Set the text in the bankRoll Label to the // amount remaining in the player's account // amtRemaining // COMPILE CHECK # 8 HERE } // ------------------------------------------------------ // 9. The newGuess() Method // ------------------------------------------------------ private void newGuess() { System.out.println("newGuess() method called."); // a. Retrieve the text from theGuess // b. Convert the text to a local int [curGuess] // c. Increment the number of tries // d. Print the number of guesses and the current guess // to theOutput // e. Test to see if curGuess is equal to theNumber // If so, then: // Call the method gameWon() // Otherwise: // Test to see if curGuess is greater than theNumber. // If so then // Print "Sorry, too high. Try lower" // Otherwise // Print "Sorry, too low. Try higher" // Set the focus to theGuess text field // Set the background color of the field to yellow // Select all of the text in the text field // COMPILE CHECK # 9 HERE } // ------------------------------------------------------ // 10. The gameWon() Method // ------------------------------------------------------ private void gameWon() { System.out.println("gameWon() method called"); // a. Print "************** WINNER ***************" // Clear the screen when this is printed. // b. Print out the amount wagered (always 1 Zipoid) // and the number of tries // c. Calculate the current winnings using a switch // statment. Use the field numTries in your // switch statement. If numTries is 1, then the // current winnings is 2, if 2 the 1.75, etc. Store // the current winnings in a local variable // d. Print the current winnings on theOutput // e. Add the current winnings to the amount remaining. // Store the result back in amtRemaining. // f. Print the player name + the amount left to output // g. Instruct the player to press the New Number button // h. Call the updateScore() method // i. Clear theGuess textfield, disable it, set its // background to white, and set focus to the // newNumber button. // COMPILE CHECK # 10 HERE } }