Please note that I do NOT edit the 1st post with the updated program, please check the later post to see the current discussion on the program. Thanks.
Well I'm back and in need - yet again - of help with a program I'm trying to create. This program is meant to simulate a mini-craps game. There are some probems though...here's what it is at the moment:
When it gets to "Push any letter key to roll again" for some reason it skips it the 1st time and does the command by itself, THEN it allows the user to hit the key to continue. Do you know what the problem is?
Another thing that I want to add to the program (I've tried to figure out how, failed at finding it) is to give the user the option to "Quit" after any roll. I don't know how to make it jump out of the loop by typing in something (like "Quit" or "Stop" etc), anyone know how to?
One last thing is that I know I still have to make it ask for a bet inside the infinate loop, I want to figure that out myself but I figured it would be best to fix the current problem and add the "Quit" function before I continue.
Thanks.
-Matt
Well I'm back and in need - yet again - of help with a program I'm trying to create. This program is meant to simulate a mini-craps game. There are some probems though...here's what it is at the moment:
Code:
//Job 35 rolldiceplus2.java
import java.util.*;
class rolldiceplus2
{
public static void main (String[]args)
{
System.out.println("The purpose of this program is to create random numbers which will simulate a rolling of dice.");
System.out.println();
Scanner bob = new Scanner(System.in);
// Create a random number maker
Random rMaker = new Random();
int bank = 1000;
int bet;
int win;
int lose;
// Ask for bet
System.out.println("You currently have $1000. How much would you like to bet?");
bet = bob.nextInt();
win = bank + bet;
lose = bank - bet;
System.out.println();
{
int die1;
int die2;
// Roll 1st die
die1 = rMaker.nextInt(6)+1;
// Roll 2nd die
die2 = rMaker.nextInt(6)+1;
System.out.println("You rolled a " + die1 + " and a " + die2);
System.out.println();
// Add both die and place the value in a variable called roll
int roll = (die1 + die2);
// Test for a winner (7 or 11)
if (roll == 7 || roll == 11)
System.out.println("You Win! You now have " + win + " in your bank");
else
// Test for a loser (2, 3, or 12)
if (roll == 2 || roll == 3 || roll == 12)
System.out.println("You Lose! You now have " + lose + " in your bank");
else
System.out.println("Your point is " + roll);
System.out.println();
// Initialize an integer vairable called point and assign it the value of roll
int point = roll;
// Set up infinite while loop for more rolls
while (true)
{
System.out.println("Push any letter key to roll again.");
String k = bob.nextLine();
System.out.println();
// Roll 1st die
die1 = rMaker.nextInt(6)+1;
// Roll 2nd die
die2 = rMaker.nextInt(6)+1;
System.out.println("You rolled a " + die1 + " and a " + die2);
// Add both die and place the value in a variable roll
roll = (die1 + die2);
// Test for a winner
if (point == roll)
{
System.out.println("You Win!");
break;
}
// Test for a loser
if (roll == 7 || roll == 11)
{
System.out.println("You Lose");
break;
}
}
}
System.out.println("Game Over");
}
}
When it gets to "Push any letter key to roll again" for some reason it skips it the 1st time and does the command by itself, THEN it allows the user to hit the key to continue. Do you know what the problem is?
Another thing that I want to add to the program (I've tried to figure out how, failed at finding it) is to give the user the option to "Quit" after any roll. I don't know how to make it jump out of the loop by typing in something (like "Quit" or "Stop" etc), anyone know how to?
One last thing is that I know I still have to make it ask for a bet inside the infinate loop, I want to figure that out myself but I figured it would be best to fix the current problem and add the "Quit" function before I continue.
Thanks.
-Matt










