0% found this document useful (0 votes)
3 views2 pages

CS115 Review

The document outlines programming assignments for a CS115 course, including a guessing game that tracks user guesses, a spinner class for board games, and a Bounce class that calculates bounce heights based on a percentage. Each assignment specifies required methods, constructors, and expected outputs. Additionally, there are design questions to answer regarding class attributes and methods for the Bounce class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

CS115 Review

The document outlines programming assignments for a CS115 course, including a guessing game that tracks user guesses, a spinner class for board games, and a Bounce class that calculates bounce heights based on a percentage. Each assignment specifies required methods, constructors, and expected outputs. Additionally, there are design questions to answer regarding class attributes and methods for the Bounce class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You need to write a test program to test the Spinner class.


3. Complete the design and coding for a Bounce class.
Rubber balls are rated with a bounce percentage which describes to what height a ball will bounce to relative to
the initial height it is dropped from. a 50% bounce percentage (the default value) means the ball will return to
half the original height after one bounce, one quarter the original height after two bounces, etc.
Create a Bounce class with necessary instance attributes and class constants, and the following methods:
 Constructors - default and non-default
 Accessors - returns values of the instance variables
 Mutators - does argument verification and assigns new values to the instance variables,
 toString method that returns a String
Bounce Percentage: 0.5
 getTable - given the initial height and bounce count, calculates and returns a multi-line, semicolon
delimited String of "bounceCount;height", one to a line, for the number of bounces specified. The height
should be three decimal places each.
If the height reaches less than one tenth of its initial height, a third field is added on that line only
";Below 1/10th initial height"
Finally, your getTable method should verify that the arguments are logically correct, else return an error
message ("getTable invalid arguments") instead of the multil-ine, semicolon delimited String.

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

You might also like