CS115 Review
CS115 Review
1. Write a program that plays a guessing game. The game will pick a random secret number between (or equal
to) 2 set values (a low limit and high limit, assume correct) and prompt the user to guess that number until he or
she guesses correctly. On each wrong guess, the game will provide feedback about whether the user guessed too
high or too low. Along the way, the program will keep track of how many guesses the user has made so far, and
will tell the total number of guesses at the end. Here are two example runs (user input underlined):
What is the low limit and high limit for the secret What is the low limit and high limit for the secret
number? 10 100 number? -50 50
Please try to guess my number. 50 Please try to guess my number. 0
Your guess (50) was too low. Your guess (0) was too low.
Please try to guess my number. 70 Please try to guess my number. 40
Your guess (70) was too low. Your guess (40) was too high.
Please try to guess my number. 85 Please try to guess my number. 30
Your guess (85) was too low. Your guess (30) was too high.
Please try to guess my number. 95 Please try to guess my number. 20
Your guess (95) was too high. Your guess (20) was too high.
Please try to guess my number. 90 Please try to guess my number. 10
Your guess (90) was too high. Your guess (10) was too low.
Please try to guess my number. 88 Please try to guess my number. 15
Your guess (88) was too high. Your guess (15) was too low.
Please try to guess my number. 87 Please try to guess my number. 16
Your guess (87) was too high. Correct! You got the answer in 7 guesses.
Please try to guess my number. 86
Correct! You got the answer in 8 guesses.
As part of your solution, you must write a function to determine the secret number within the user’s range.
2. Many board games use a random spinner to determine a player’s move. It is easy to
represent a spinner as a Java object.
You are given a class that represents a fair, "n"-section spinner with the following
variables and methods:
instance variables - the size of the spinner and what number the arrow is
pointing to.
class constants for the default number of sections (10), and for the default
arrow location (0).
constructors - default & non-default (user argument for the size)
accessors getArrow, getSize
mutator setArrow - assigns what the arrow is pointing to.
toString - returns a String with a message and size and the arrow location, i.e.
"Size=10 Arrow=4"
spin - a "calculation method" that will randomly spin the spinner.
Here is sample String returned for getTable(100,5) on a Bounce object with bounce percentage=.5 Hint: Use a
"\n" at the end of every line.
0;100.000
1;50.000
2;25.000
3;12.500
4;6.250;Below 1/10th initial height
5;3.125
Here is sample String returned for getTable(100,.0) on a Bounce object with bounce percentage=.5
getTable invalid arguments
3a. Class Design - Answer the following questions for the problem. Type your answers in the text box:
1. What are the instance attributes, their data types and valid ranges?
2. What are instance methods needed, their arguments and return types?
3. What are the class constants needed, their data type and value?
3b. Class Coding - Implement your class design. Make sure to test your code on all the test cases provided in
BounceTest.java