[Solved] CS2040S Guessing Game

$25

File Name: CS2040S_Guessing_Game.zip
File Size: 197.82 KB

SKU: [Solved] CS2040S Guessing Game Category: Tag:
5/5 - (1 vote)

Problem 0. Guessing Game Lets play a game! Weve written up a program on the server that randomly selects a number between 0 to 1000 (inclusive). Then, it will ask your program to make a guess, which is going to be done by calling the public int guess() function. Your program will then have to return a number that is its guess. Then, the server will either terminate or respond. The details for what happens are listed below.

  • If your programs guess was too low, then the server will call your programs public void update(int answer) method with answer = 1.
  • If your programs guess was too high, then the server will call your programs public void update(int answer) method with answer = 1.

There will be at most 10 rounds of such interaction. If your program manages to guess the number correctly within the 10 rounds, then the server will terminate with acceptance. Else. the server will terminate with rejection.

Here is an example execution between a possible program[1] and the server (whose mystery number is 123):

  1. Server calls public int guess() and obtains 0
  2. Server calls public void update(-1) because 0 < 123
  3. Server calls public int guess() and obtains 200
  4. Server calls public void update(1) because 200 > 123
  5. Server calls public int guess() and obtains 124
  6. Server calls public void update(1) because 124 > 123
  7. Server calls public int guess() and obtains 123
  8. Server terminates and accepts.

In the above execution, the program only used 4 guesses. If the program uses 10 guesses and still does not get the right value the server will terminate and reject instead. Implement public int guess() and public void update(int answer) to solve this problem. As a mildly important note: your program will probably need some way of remembering past responses. In this scenario making use of instance variables to store your state would be useful.

1

[1] your program neednt execute like the one below

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2040S Guessing Game[Solved] CS2040S Guessing Game
$25