Assignment 0

CSIS 10B
Assignment 0 Java Review
Due: next Wed
In Class Drills (0 points):
COINS
1)
2)
3)
4)
5)
Use Math.random() to model a coin toss
Find the total number of heads in 1000 tosses
Make a coin class with a constructor, flip, and getValue method
Repeat #2 using an object of class coin
Challenge: Determine the longest run of “heads” in 1000 tosses
HANGMAN
1) Read in a target string, for example “antelope”
2) Construct a new string called match that has the same length as target but made up entirely
of the dash character. For example “--------“
3) Read in a char variable called guess
4) Make a loop that constructs a newMatch string by visiting each character in target and
turning on in newMatch those letters that are the same as guess.
5) Only allow 8 guesses for player to succeed.
Assignment (10 points) Do either Basic or one of the Advanced.
Basic
1)
2)
3)
4)
5)
Use Math.random() to model the throw of two dice
Find the total number of “snake eyes” or two ones in 1000 throws
Make a TwoDice class with a constructor, roll and getValue method
Repeat #2 using an object of your TwoDice class
Determine the number of throws needed to get “snake eyes”. To do this, make a while loop
that rolls dice until the goal is reached. Determine the number of times this loop repeated
(put a counter nTimes in it), and output this value
6) Now find the average number of throws to get “snake eyes”. Put your solution to 5 inside a
for loop that repeats 1000 times, and computes a running sum of the nTimes. After the for
loop completes, simply divide the sum by 1000 and that is the average number of rolls
needed.
Advanced: Klondike
If you would like a more difficult challenge, try implementing this game in “Solitaire” mode, with the
computer being the “banker” and the player placing bets agains the house and building as much wealth
as possible. A FiveDice class can be very helpful, especially if it internally determines the numeric
outcome of a roll, such as 100 for five ones, and on down. A toString() method will also be useful in
outputing the current state of the dice...
Sometimes known as Counter Klondike if played on a shop counter and Casino Klondike when played in a
casino. This is a gambling game that was played in cheap casinos in frontier America using five dice. The
combinations or hands used are similar to Poker or Indian Dice but with some omissions.
Play:
A banker rolls the dice first and players then roll the dice in turn trying to beat the combination first
thrown. Only one throw is allowed. Numbers rank high to low as 1, 6, 5, 4, 3, 2. Any die not used in a
combination is ignored. If a player rolls a combination equal to the banker's the banker wins. The
payoffs are made by the banker at even odds. i.e. players get their stake back with an equal amount.
Winning combinations in descending order are as follows.
o
o
o
o
o
o
Five-of-a-kind
Four-of-a-kind
Full House (Three-of-a-kind and a pair)
Three-of-a-kind
Two pairs
One pair
Super Advanced: Cryptoquote
visit: http://www.eastoftheweb.com/cgi-bin/top_scores.pl?game=cryptoquote
Like hangman, you can enter a target string, but now the string must be encoded by mapping letters to
codes. A String might be the simplest way of representing the code associations. Every time a new letter
is entered add it to the end of the String, followed by a random letter that is not currently in use.
For example a code string asermny2 would represent linking swapping a with s, letter e with r, letter
m with n and letter y with 2. The even cells could then be searched while encrypting, and the odd cells
swapped in for the coded string. Just one possibility.