$24
A Game of Chance:
“Chuck-a-luck”
Reminders:
Submit your java file name EXACTLY as specified (ChuckALuck.java) using the ‘Assignments’ link of the course conneX site. ** Don’t forget to follow the Style Guidelines posted – this is part of the requirements of every assignment.
It is OK to talk about your assignment with your classmates, and you are encouraged to design solutions together, but each student must implement their own solution. We will be using plagiarism detection software on your assignment submissions.
Learning Outcomes:
When you have completed this assignment, you should understand:
How to implement conditional statements (if-statements and if/else-statements)
How to compare Strings.
How to analyze the flow of choices to ensure correct program logic.
How to design a suite of tests that will check the various cases in a branching program (i.e. one that contains conditional statements).
Logical decomposition using methods.
How to design and use indefinite loops.
How to generate random numbers.
Assignment Requirements:
This assignment requires you to implement the game of “Chuck-a-luck”.
In order for you assignment to be graded, we require you to use the following code for your main method…
public static void main(String args[]) { Scanner scan = new Scanner(System.in);
Random rand = new Random(System.currentTimeMillis()); play(scan, rand);
}
And your implementation must include the following method EXACTLY as shown…
/*
PURPOSE:
to play
the chuck a
luck game
user for the
INPUT:
Scanner
scanner, to
collect
input from the
the bet
amount
and if they want
to continue playing
OUTPUT:
Random randomObject, to
simulate dice roll
bankroll
prompts
to ask
user
for
bet
and
updates of
*/
public static void play(Scanner scanner, Random randomObject)
You must decompose your program into multiple methods, but you are free to choose what those methods look like. Remember, if a method you are writing needs a Scanner or a Random object you can pass the ones you have in your play method to that next method. For example..
public static void play(Scanner scanner, Random randomObject) { myMethod1(scanner);
myMethod2(randomObject);
}
public static void myMethod1(Scanner scan) { String s = scan.next();
}
public static void myMethod2(Random rand) { int num = rand.nextInt(10);
}
Programming Problem Description:
Rules for Chuck-a-luck are available here: http://en.wikipedia.org/wiki/Chuck-a-luck. Your version of
Chuck-a-luck only needs to implement a Single Dice Bet and must perform the following steps:
Ask the player to input how much money they want to add to start their bankroll (how much money they have in total to play with).
Take a bet from the player via the command line (again, bets are decimal values). The player will input a number between 1 and 6 and the amount of money they want to bet. NOTE: you must ensure they pick a valid number and they can’t bet more money than is available in their bankroll.
Roll the three dice, determine how many of the dice match the player’s number and then calculate the player’s winnings. NOTE: Your “dice” are implemented with a random number generator that simulates a 6-sided die.
a. To calculate winnings, follow the Single Dice Bet odds:
1 dice matching player gets 1:1 odds on their wager
2 dice matching player gets 2:1 odds on their wager
3 dice matching player gets 10:1 odds on their wager
0 dice matching player loses their wager on their wager
Your game must keep track of and print out: a) how many bets the player made and b) the player’s bankroll after each bet (this should print out as decimal value with two significant figures (ie. $5.67) HINT: check out String.format (http://stackoverflow.com/questions/7548841/round-a-double-to-3-significant-figures)
The game should continue to allow the player to bet if: a) they still want to and b) they still have money in their bankroll. ‘
The program (ChuckALuck.java) must…
Use the Random class to simulate a roll of the die (i.e. a random number between 1 and 6). See the text to learn how to use this class.
Use if statements and while loop. Other loops and condition statements can be used as needed as well.
Provide informative prompts when user input is required. The user will input “y” or “n” (or some similar String values) for whether or not to bet again.
Give informative output, such as: the number rolled on each die, the amount of money won/lost at the end of each turn, the player’s bankroll total at the end of each turn, and if the player is up and by how much OR if the player is down and by how much.
Be logically decomposed into smaller parts, using methods.
Be well documented, following the style guidelines.