This will be a six part program. Each section should take no more than one
day. Most will only take minutes.
Part 1 is due 9/19 and Part 6 will be due on or before 9/26.
Each part will be graded independently. Points will be deducted for late submission.
You are welcome to look for help, even from other students, but everyone should
work independently and submit their own work. All commands are from lesions
1-12.
When each part is completed send the code as a inline attachment (copy and
paste in body) to me at mytests1@yahoo.com no later than 7pm.
Insert your name and the program name in the subject line.
Include any question or comments in the top of the body of your email.
When you finish you should have a game called “LuckyDice”.
It will roll two dice showing the total of the two die.
A roll of 7 or 11 (lucky numbers) will gain you 5 points but any other roll
you loose 5 points.
It will show you how many times you have rolled the dice and your total score.
You will be allowed to play as many times as you like without restarting the
game.
Every section should include comments to explain functions.
Computer output will be in blue for clarity here
only, your output will be black.
Let's get started.
Program name DiceGame1
Write a program that will display the results of two
random number generators.
The numbers will be in the range of 1-6. You will show each number and
the total.
The output should look like the following:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to the 7-11 Game
Random 1 = 3 | Random 2 = 6 | Total for Random numbers is = 9 |
Part 2Program name DiceGame2 |
There are 2 "|" and 7 "-" in this first segment The finished number 5 die should look like this |
Now replacing the numbers with our dice we can recode the output to look something like this: Welcome to the 7-11 Game |
||
Random # 1 = 1 | Random # 2 = 6 | The Total is = 7 |
|-------| |-------| You rolled a - 7 |
Program name DiceGame3
Add the option of playing the game over and over. (hint - remember our guessing game)
Format it to look like this:
Do you want to play again? (y for yes n for no) (We should allow either upper or lower case here)
(hint - sample code only Yours will differ)
//Asks if the player wants to play again
for(;;)//three expressions of the for loop are optional this becomes an infinite loop
{
System.out.println(""); //Spacer
System.out.print("Do you want to play? (y for yes n for no) ");
play = kbReader.next();
if(play.equalsIgnoreCase("y") || play.equalsIgnoreCase("n"))
{
break;
}
else
{
System.out.println("Only type y or n");
continue;
}
}
if(cash == 0){
break;
}
Lets give everyone who plays the game 100 points to start with. This would be a good time to tell them the rules. For each roll we will add 10 points for a winning roll of a 7 or 11 but subtract 5 points for any other combination.
(hint - sample code only Yours will differ)
//Tells player if they won or not
d1PlusD2 = d1 + d2;
if(d1PlusD2 == 7 || d1PlusD2 == 11)
{
cash = (cash + 10);
System.out.println("You have $" + cash + ".00 left");
System.out.println("");// Spacer
System.out.println( "You rolled a - Lucky " + d1PlusD2 + " - YOU WIN $10.00 ");
}
else {
System.out.println("");
System.out.println("You rolled a - " + d1PlusD2 + " - Sorry you loose $5.00");
cash = (cash - 5);
System.out.println("You have $" + cash + ".00 left");
}
Sample output should look like this:
Do you want to play the dice game? (y for yes, n for no) y
If you roll a Lucky 7 or 11 you win 10 points but
any other roll and you loose 5 points.
|-------|
| * |
| * |
| * |
|-------|
|-------|
| * * |
| |
| * * |
|-------|
You rolled a - Lucky 7 - YOU WIN 10 points
You have 110 points left
Do you want to play again? (y for yes n for no)
OR
You rolled a - 9 - Sorry you loose 5 points
You have 105 points left
Do you want to play again? (y for yes n for no)
Program name DiceGame4
Error trapping time. What if the input was not a "y" or "n". What if they input "yes" or "sure".
We need a way of looking to see if the input is a acceptable input before it would jump to an error.
If it is not remind them only a "y" or "n" is acceptable input.
Sample output:
Do you want to play again? (y for yes n for no) sure
Please only type y or n
Do you want to play again? (y for yes n for no)
Program name DiceGame5
Just for fun lets make the points look like play money. Add a dolor sign and some zeros.
Sample output::
You rolled a - Lucky 7 - YOU WIN $10.00
You have $110.00 left
New program name LuckyDice
All games have to have an ending. Show me the money and tell me how many rolls it took.
|-------|
| * * |
| * * |
| * * |
|-------|
|-------|
| |
| * |
| |
|-------|
You rolled a - Lucky 7 - YOU WIN $10.00
You have $110.00 left
Do you want to play again? (y for yes n for no) n
Sample ending:
You have $110.00 in Cash
You rolled the dice 4 times
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
You are welcome to make additions to improve this game for Bonus points.
Note any improvements in the comments section at the top of the game.