SlideShare ist ein Scribd-Unternehmen logo
1 von 3
CIS/355 iLab 5 of 6



STEP 1: GuessGame

Write a program named GuessGame.java that plays the game “guess the number” as follows:
Your program chooses the number to be guessed by selecting an integer at random in the range 1–
1000. The program then displays the following in a label.

I have a number between 1 and 1000 -- can you guess my number?

Please enter your guess: ____________________

A JTextField should be used to input the guess. A JButton must be provided to allow the user to
press each time a guess is entered. 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 indicates that the user is
getting colder. A JLabel should display either Too High or Too Low to help the user zero in on the
correct answer. When the user gets the correct answer, Correct! should be displayed, and the
JTextField used for input should be cleared and changed to be uneditable. Also, a JButton should be
provided to allow the user to play the game again. When the New Game JButton is clicked, a new
random number should be generated and the input JTextField changed to be editable. A JButton
must be provided to allow the user to exit the application. Also provide a count of the number of
guesses the user entered when the correct number is guessed.

Grading Rubric
          GuessGame                 Points                          Description

                                             Must contain program's name, student name, and
Standard header included              1
                                             description of the program

Program compiles                      1      Program does not have any error

Program executes                      1      Program runs without any error

                                             GUI contains the label with the initial question, the label
GUI contains the required
                                      2      for the input field, and the label for the Too high or Too
labels
                                             low message

GUI contains input text field
                                      2      GUI contains the input field for entering the guess
for the guess

GUI contains the Guess, New                  GUI contains the Guess button, New Game button, and
                                      3
Game, and Exit buttons                       Exit button

Each button handles the
                                             Each button handles and processes its corresponding
corresponding events                  6
                                             behavior
properly

Program displays the correct          4      Program displays the correct messages, changes the
output                                      colors appropriately, and displays the count of guesses

                         Subtotal     20



STEP 2: Text File I/O (20 points)

Write a program called TextFileIO.java to create a file named numbers.dat. Then create an
algorithm that writes all even numbered integers from 1 to 100, separated by a comma. After the
file has been created, close and reopen the file and display the results to the screen. After the
results have been displayed append the odd number integers from 1 to 100, separated by a comma
to the end of the file. Reopen the file and display the results. The contents of the file should be the
even numbers from 1 to 100 separated by a comma followed by the odd number from 1 to 100
separated by a comma. The output of this program would be something like the following

2,4,6,8,10,12,14,……,98,100
2,4,6,8,10,12,14,……,98,100,1,3,5,7,9,……..97,99

Grading Rubric
                 Text File I/O                  Points                   Description

                                                         Must contain program’s name, student name,
Standard header included                           1
                                                         and description of the program

Program compiles                                   2     Program does not have any error

Program executes                                   2     Program runs without any error

Program creates "numbers.dat" file                 2     The file numbers.dat exists and is readable

Program writes all even number
                                                         All even numbers from 1 to 100 are written
integers from 1 to 100, separated by               2
                                                         to the file. A comma separates each number.
commas

                                                         The file is closed after even numbers are
File is closed                                     1
                                                         processed

                                                         The file is re-opened for reading the even
File is re-opened for reading                      1
                                                         numbers and commas

                                                         Program displays even numbers from 1 to
Program displays even integers                     1
                                                         100 separated by commas

Odd numbers from 1 to 100 separated                      Odd numbers from 1 to 100 are appended to
                                                   2
by commas are appended                                   the file. A comma separates each number.

                                                         The file is closed after odd numbers are
File is closed                                     1
                                                         processed

                                                         The file is re-opened for reading the even
File is re-opened for reading                      1
                                                         and odd numbers separated by commas
The contents of the file are displayed
File contents are displayed                 1    correctly, showing each number separated by
                                                 a comma

                                                 Program displays the correct output as
Correct output is displayed                 5
                                                 described above

                               Subtotal     20


CLICK HERE TO GET THE SOLUTION !!!!!!!!!!

Weitere ähnliche Inhalte

Mehr von ashhadiqbal

Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7ashhadiqbal
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7ashhadiqbal
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7ashhadiqbal
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7ashhadiqbal
 

Mehr von ashhadiqbal (8)

Ilab 2 of 7
Ilab 2 of 7Ilab 2 of 7
Ilab 2 of 7
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7
 
PRG/421 Week 4
PRG/421 Week 4PRG/421 Week 4
PRG/421 Week 4
 
PRG/421 Week 2
PRG/421 Week 2PRG/421 Week 2
PRG/421 Week 2
 
PRG/421 Week 1
PRG/421 Week 1PRG/421 Week 1
PRG/421 Week 1
 

Cis 355 ilab 5 of 6

  • 1. CIS/355 iLab 5 of 6 STEP 1: GuessGame Write a program named GuessGame.java that plays the game “guess the number” as follows: Your program chooses the number to be guessed by selecting an integer at random in the range 1– 1000. The program then displays the following in a label. I have a number between 1 and 1000 -- can you guess my number? Please enter your guess: ____________________ A JTextField should be used to input the guess. A JButton must be provided to allow the user to press each time a guess is entered. 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 indicates that the user is getting colder. A JLabel should display either Too High or Too Low to help the user zero in on the correct answer. When the user gets the correct answer, Correct! should be displayed, and the JTextField used for input should be cleared and changed to be uneditable. Also, a JButton should be provided to allow the user to play the game again. When the New Game JButton is clicked, a new random number should be generated and the input JTextField changed to be editable. A JButton must be provided to allow the user to exit the application. Also provide a count of the number of guesses the user entered when the correct number is guessed. Grading Rubric GuessGame Points Description Must contain program's name, student name, and Standard header included 1 description of the program Program compiles 1 Program does not have any error Program executes 1 Program runs without any error GUI contains the label with the initial question, the label GUI contains the required 2 for the input field, and the label for the Too high or Too labels low message GUI contains input text field 2 GUI contains the input field for entering the guess for the guess GUI contains the Guess, New GUI contains the Guess button, New Game button, and 3 Game, and Exit buttons Exit button Each button handles the Each button handles and processes its corresponding corresponding events 6 behavior properly Program displays the correct 4 Program displays the correct messages, changes the
  • 2. output colors appropriately, and displays the count of guesses Subtotal 20 STEP 2: Text File I/O (20 points) Write a program called TextFileIO.java to create a file named numbers.dat. Then create an algorithm that writes all even numbered integers from 1 to 100, separated by a comma. After the file has been created, close and reopen the file and display the results to the screen. After the results have been displayed append the odd number integers from 1 to 100, separated by a comma to the end of the file. Reopen the file and display the results. The contents of the file should be the even numbers from 1 to 100 separated by a comma followed by the odd number from 1 to 100 separated by a comma. The output of this program would be something like the following 2,4,6,8,10,12,14,……,98,100 2,4,6,8,10,12,14,……,98,100,1,3,5,7,9,……..97,99 Grading Rubric Text File I/O Points Description Must contain program’s name, student name, Standard header included 1 and description of the program Program compiles 2 Program does not have any error Program executes 2 Program runs without any error Program creates "numbers.dat" file 2 The file numbers.dat exists and is readable Program writes all even number All even numbers from 1 to 100 are written integers from 1 to 100, separated by 2 to the file. A comma separates each number. commas The file is closed after even numbers are File is closed 1 processed The file is re-opened for reading the even File is re-opened for reading 1 numbers and commas Program displays even numbers from 1 to Program displays even integers 1 100 separated by commas Odd numbers from 1 to 100 separated Odd numbers from 1 to 100 are appended to 2 by commas are appended the file. A comma separates each number. The file is closed after odd numbers are File is closed 1 processed The file is re-opened for reading the even File is re-opened for reading 1 and odd numbers separated by commas
  • 3. The contents of the file are displayed File contents are displayed 1 correctly, showing each number separated by a comma Program displays the correct output as Correct output is displayed 5 described above Subtotal 20 CLICK HERE TO GET THE SOLUTION !!!!!!!!!!