12 14_guessnumber_medium - agarmstrong21/agarmstrong_swd_2019 GitHub Wiki

12-14_GuessNumber_Medium

Portfolio Home Page

Problem Statement Medium

12.14 (Guess-the-Number Game) Write an application that plays "guess the number" as follows: Your application chooses the number to be guessed by selecting an integer at random in the range of 1-1000. The application then displays the following in a label:

  • I have a number between 1 and 1000. Can you guess my number?
  • Please enter your first guess.

A JTextField should b eused to input the guess. As each guess is input, the background color should change to either red or blue. Red indicates that the user is getting "warmer," and blue, "Colder." A Jlabel should display either "Too High" or "Too Low" to help the user zero in. When the user gets the correct answer, "Correct!" should be displayed, and the JTextField used for input should be changed to be uneditable. A JButton should be provided to allow the user to play the game again. When the JButton is clicked, a new random number should be generated and the input JTextField changed to editable.

User Documentation

This program creates a game that is fun for everyone. GuessNumberDriver creates a GUI that enables the user to enter values to guess a randomly generated integer between 1 and 1000. Whenever the user guesses higher than the their last guess but still lower than the answer, the window turns red. Whenever it is lower than both, it turns blue. When the user enters a value that is lower than their previous guess but still higher than the answer, the window turns red. The window will turn blue when the guess is higher than both. Lastly, when the guess is correct, the window is green. You are able to reset the game whenever.

Developer Documentation

GuessNumberDriver will be called to create a visible window with the logic implemented. GuessNumberDriver called GuessNumber class. A FlowLayout is used to put all the TextFields on the window. Given is randomly generated and the previous input is equal to the Given for the first time. When the user inputs a valid integer in the text field, the program will compare the valid with pinput and given to see if it is close, far, or the answer of given. Whenever it is close, the window turns red, whenever it is far away, the window turns blue, and the window turns green when the guess is answered. A TextFieldHandler is the logic behind this. A ButtonHandler keeps track of the reset button. When pressed, the given is reset to a different random integer and the window turns white.

Java Docs

The java documents are served from a local web server on this machine. To start the web server, navigate to the directory immediately above where the source code is checked out (i.e. ~/git ) and then use "python -m SimpleHTTPServer" in that directory.

cd ~/git
python -m SimpleHTTPServer&

Note: if you are running python 3 (which you can check via opening a terminal and typing: python --version), then the command is:

python3 -m http.server

JavaDocs for 12-14_GuessNumber_Medium

Source Code

Source Code for 12-14_GuessNumber_Medium