Hello guys! I am a beginner in Java with a little experience in programming and from the first time i loved java so i am trying to improve my shelf reading some books firstly and maybe later make some bigger projects with help from tutorials! But now i am just reading the book Absolute Java and i am stacked at a example so i would like some advice...by the way i am using only cmd for compile since i think that i should move to netbean a bit more later!!!
The program that i made it is about the Game of craps that it dice game...
Specificly "
In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are
rolled; the first roll of the dice in a craps round is called the “come out roll.”
A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12
automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number
becomes “the point.” The player keeps rolling the dice until either 7 or the point is
rolled. If the point is rolled first, then the player wins the bet. If a 7 is rolled first,
then the player loses.
Write a program that simulates a game of craps using these rules without human
input. Instead of asking for a wager, the program should calculate whether the
player would win or lose. The program should simulate rolling the two dice and
calculate the sum. Add a loop so that the program plays 10,000 games. Add
c ounters that count how many times the player wins, and how many times the
player loses. At the end of the 10,000 games, compute the probability of winning
[i.e., Wins / (Wins + Losses)] and output this value. Over the long run, who
is going to win the most games, you or the house?"
I am half done it expect the part of calculating the wins/looses and the loop of 10 000 game that it is unnecessary!
I am trying to "play" with the dices! So there is my code
import java.util.Scanner; import java.util.Random; public class GameCraps { public static void main(String[] args) { Random generator=new Random(); Scanner keyboard=new Scanner(System.in); System.out.println("**Game of Craps**"); int r=keyboard.nextInt(); do{ int dice1=generator.nextInt(6); int dice2=generator.nextInt(6); } while(r==1); int sumdices=dice1 + dice2; if(sumdices==7 || sumdices==11) { System.out.println(sumdices); System.out.println("We have a winner's come out roll!"); System.out.println("Player wins!"); System.exit(0); } if(sumdices==2 || sumdices==3 || sumdices==12 ) { System.out.println(sumdices); System.out.println("We have a looser's come out roll!"); System.out.println("Player looses!"); System.exit(0); } if(sumdices==4 || sumdices==5 || sumdices==6 || sumdices==8 || sumdices==9 || sumdices==10) { System.out.printf("%d",sumdices); System.out.println("A point is setted!"); int point=sumdices; } System.out.println("reroll please"); r=keyboard.nextInt(); do { int dice1=generator.nextInt(6); int dice2=generator.nextInt(6); int newsumedices=dice1+dice2; } while(r==1); System.out.println(newsumedices); if(newsumedices==point) { System.out.println("You catched the point!You win"); System.exit(0); } else if (newsumedices==7) { System.out.println("Bad roll m8!!!You loose"); System.exit(0); } } }
could you advice me?
When i am compiling via javac on cmd throws 6 erros of the type :
GameCraps.java:17: error: cannot find symbol
int sumdices=dice1 + dice2;
^
symbol: variable dice1
location: class GameCraps
GameCraps.java:17: error: cannot find symbol
int sumdices=dice1 + dice2;
^
symbol: variable dice2
location: class GameCraps
GameCraps.java:51: error: cannot find symbol
System.out.println(newsumedices);
^
symbol: variable newsumedices
location: class GameCraps
GameCraps.java:53: error: cannot find symbol
if(newsumedices==point) {
^
symbol: variable newsumedices
location: class GameCraps
GameCraps.java:53: error: cannot find symbol
if(newsumedices==point) {
^
symbol: variable point
location: class GameCraps
GameCraps.java:57: error: cannot find symbol
else if (newsumedices==7) {
^
symbol: variable newsumedices
location: class GameCraps
6 errors