Algorithmic Problem Solving - Homework 2 Computer Science | CSCI 2310, Assignments of Computer Science

Material Type: Assignment; Professor: Smith; Class: Algorithmic Problem Solving; Subject: Computer Science; University: East Carolina University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-rwi
koofers-user-rwi 🇺🇸

5

(1)

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 2310
Homework 2
Write a Java program complete with full documentation to play the game, "GUESS THE
NUMBER", with a human user. Your program must randomly select a target integer from 1
to 64, and it is up to the program user to guess the correct number. After each guess, the
program must tell the user if the guess is too high, too low, or correct. A sample interaction
would be the following (suppose the random target number selected was 40). The user input
will be underlined.
Welcome to the GUESS THE NUMBER program.
Make a guess (from 1 to 64) and press RETURN
32
Your guess of 32 is too low.
Make a guess (from 1 to 64) and press RETURN
48
Your guess of 48 is too high.
Make a guess (from 1 to 64) and press RETURN
40
40 is CORRECT!!
In order to obtain the random number to be guessed, download GuessNum.java from the CSCI
2310 web page. This contains the definition of a code segment that will provide you with a
random number to guess. You will have to include this code appropriately as part of your overall
program for playing the game. It will define a variable named target that will contain the number
to guess.
Note that as part of the execution of this code it will prompt you with the statement “Enter integer
seed from 1 to 100000”. The purpose of this is to initialize the random number generator. This
will not be the actual random number generated. What you are able to rely on is that every time
you execute the program and input a particular number as the integer seed, the random number
generated will always be the same.
ERROR HANDLING: This program should do the following type of error handling:
The program normally terminates when the person makes a correct guess. However, we
do not wish to waste computing resources on a user who is not guessing intelligently.
Define a constant MAXGUESSES and set it to 8. See page 57 of your text for
information about defining constants. Whenever the number of guesses that a user makes
will exceed MAXGUESSES without having given a correct guess, the program should
issue an appropriate message saying that the user has exceeded the maximum number of
guesses, and terminate the program.
pf2

Partial preview of the text

Download Algorithmic Problem Solving - Homework 2 Computer Science | CSCI 2310 and more Assignments Computer Science in PDF only on Docsity!

Computer Science 2310

Homework 2

Write a Java program complete with full documentation to play the game, "GUESS THE NUMBER", with a human user. Your program must randomly select a target integer from 1 to 64, and it is up to the program user to guess the correct number. After each guess, the program must tell the user if the guess is too high, too low, or correct. A sample interaction would be the following (suppose the random target number selected was 40). The user input will be underlined.

Welcome to the GUESS THE NUMBER program.

Make a guess (from 1 to 64) and press RETURN 32 Your guess of 32 is too low.

Make a guess (from 1 to 64) and press RETURN 48 Your guess of 48 is too high.

Make a guess (from 1 to 64) and press RETURN 40 40 is CORRECT!!

In order to obtain the random number to be guessed, download GuessNum.java from the CSCI 2310 web page. This contains the definition of a code segment that will provide you with a random number to guess. You will have to include this code appropriately as part of your overall program for playing the game. It will define a variable named target that will contain the number to guess.

Note that as part of the execution of this code it will prompt you with the statement “Enter integer seed from 1 to 100000”. The purpose of this is to initialize the random number generator. This will not be the actual random number generated. What you are able to rely on is that every time you execute the program and input a particular number as the integer seed, the random number generated will always be the same.

  • ERROR HANDLING: This program should do the following type of error handling:

The program normally terminates when the person makes a correct guess. However, we do not wish to waste computing resources on a user who is not guessing intelligently. Define a constant MAXGUESSES and set it to 8. See page 57 of your text for information about defining constants. Whenever the number of guesses that a user makes will exceed MAXGUESSES without having given a correct guess, the program should issue an appropriate message saying that the user has exceeded the maximum number of guesses, and terminate the program.

  • Tips on program development. Develop a simple program that can use the provided code to determine the random number to be guessed. Add some code to print out the number and also add your initial logic for the input of a guess and properly analyzing it (without the loop). Then modify the program so that you can play the game in its basic form (i.e., the user keeps guessing until correct). You should complete this by the end of the weekend. Finally, add the error handling.
  • Your program will be evaluated on the basis of its correctness, the neatness and informativeness of its output and messages (remember the possible error message), and your adherence to the programming standards of this class.
  • Submission information: Name your file GuessNum.java and place in a separate subdirectory with a name of your choice. Use the command submit h2 GuessNum.java to electronically submit your assignment.
  • This problem is worth 75 points. A program that does not compile will receive zero points. Do not delay in starting on this program.

DUE DATE: March 26 at the start of class.