I created a new google web application project (using eclipse) and noticed the code runs in the .server package. I have a slot machine game i wrote in java and am trying to implement it into GWT, but the syntax seems to be totally different. (for example, i noticed \n doesn't work)
Here is the code i want to implement - how the heck would i do that?
// clear console
static void clearConsole()
{
for (int i=0; i<25; i++)
{
System.out.println("\n");
}
}
// actual slot machine algorithm
static void slots()
{
Scanner input = new Scanner (System.in);
char newGame = ' ';
int chips = 100;
int bet = 0;
do{
System.out.println( "Try your luck on the SLOT MACHINE." +
"\nLine up (=^^=) or ))<>(( symbols to win big!\n\n" +
"You currently have " + chips + " chips.\nHow much do you want to bet? ");
//check for accidental char input
try{
bet = input.nextInt();
}
catch(Exception e){
input.nextLine();
System.out.println("NOT A VALID NUMBER\nHow much do you want to bet? ");
bet = input.nextInt();
}
if (bet<=chips && bet>0){
// to add some realism, slot machine will not execute until 'enter' pressed
// then console cleared
input.nextLine();
System.out.println( "\nPress 'enter' to start the slot machine.");
input.nextLine();
clearConsole();
String[] machine = {"(=^^=)", "(=^^=)", "))<>((", " XXXX ", " XXXX ", " :^{) ",
" :^{) ", " (>_<)", " (>_<)", " [-O-]", " [-O-]"};
Random rand = new Random();
int slot1 = rand.nextInt(11);
int slot2 = rand.nextInt(11);
int slot3 = rand.nextInt(11);
int slot4 = rand.nextInt(11);
int slot5 = rand.nextInt(11);
int slot6 = rand.nextInt(11);
int slot7 = rand.nextInt(11);
int slot8 = rand.nextInt(11);
int slot9 = rand.nextInt(11);
System.out.println( "-----------------------");
System.out.printf( "%-7s %-7s %-7s %n%n", machine[slot1], machine[slot2], machine[slot3]);
System.out.printf( "%-7s %-7s %-7s %n%n", machine[slot4], machine[slot5], machine[slot6]);
System.out.printf( "%-7s %-7s %-7s %n", machine[slot7], machine[slot8], machine[slot9]);
System.out.println( "-----------------------\n\n\n\n");
// 3 wild cards
if (slot4 == 2 && slot5 == 2 && slot6 == 2 ){
bet = bet*100;
chips = chips + bet;
System.out.println( "JACKPOT! ");
}
//3 cats (inclusive of wild card)
else if ( slot4 <3 && slot5 <3 && slot6 <3 ){
bet = bet*5;
chips = chips + bet;
System.out.println( "YOU WIN! ");
}
// 3 of any other symbol (inclusive of wild card)
else if( ((slot4==2 || slot4==3 || slot4==4) && (slot5==2 || slot5==3 ||
slot5==4) && (slot6==2 || slot6==3 || slot6==4))
|| ((slot4==2 || slot4==5 || slot4==6) && (slot5==2 || slot5==5 ||
slot5==6) && (slot6==2 || slot6==5 || slot6==6))
|| ((slot4==2 || slot4==7 || slot4==8) && (slot5==2 || slot5==7 ||
slot5==8) && (slot6==2 || slot6==7 || slot6==8))
|| ((slot4==2 || slot4==9 || slot4==10) && (slot5==2 || slot5==9 ||
slot5==10) && (slot6==2 || slot6==9 || slot6==10)) ){
bet = bet*3;
chips = chips + bet;
System.out.println( "YOU WIN! ");
}
// 2 cats
else if ( slot4<2 && slot5<2 || slot4<2 && slot6<2 || slot5<2 && slot6<2){
bet = bet*2;
chips = chips + bet;
System.out.println( "YOU WIN! ");
}
// 1 cat
else if ( slot4 < 2 || slot5 < 2 || slot6 < 2 ){
chips = chips + bet;
System.out.println( "YOU WIN! ");
}
// nothing
else{
chips = chips - bet;
System.out.print( "You Lose... ");
}
// display current amount of chips
System.out.println( "You have " + chips + " chips.");
}else{
System.out.println( "You do not have enough chips to make that bet!");
}
if (chips > 0){
System.out.println( "\nDo you wanna play this game again? (y/n): ");
newGame = input.next().charAt(0);
clearConsole();
}
} while (newGame =='y' && chips > 0 );
input.close();
System.out.println( "\nGame Over\n\n");
}
You could replace System.out.println with putting raw text (not even HTML) into an element with fixed space etc (something like the "pre" element).
I'd suggest you switch to something like Button for "enter", "y"/"n"... and and DoubleBox for the amount they want to bet.
There may be a more general "console" in browser approach but it would be a bit odd?
Maybe best starting with one of the GWT samples and slowly converting to what you want? Quite a bit of bootstrapping to get a GWT app up and running.
Related
I have a decent sized while loop that is supposed end when the answer to the following prompt is answered 'N' for no. Adding Break; after the last line of code causes my program to spit out error codes after reaching this prompt and entering a character. The issue may have to do when formatting as I get errors stating things like " Enter 'Y' to add another laptop to your purchase or 'N' to exit: y
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
Here is the while loop:
while (Character.toUpperCase(cont) == 'Y') {
dateTime = Calendar.getInstance();//Obtains current year
System.out.printf("%nTOP LAPTOPS OF %tY"
+ "%n%n1. %-23s %7s $%,9.2f"
+ "%n2. %-23s %8s %,9.2f"
+ "%n3. %-23s %8s %,9.2f"
+ "%n4. %-23s %8s %,9.2f"
+ "%n5. %-23s %8s %,9.2f"
+ "%n%nEnter your choice: ",
dateTime,
"HP Envy 13", " ", 799.99,
"Asus Zen Book 13 UX33FA", " ", 849.99,
"Dell XPS 13", " ", 989.99,
"Alienware Area 51-m", " ", 1999.99,
"Razer Blade Stealth", " ", 1299.00); //Prompt 1
choice = input.nextInt(); //Input is assigned to choice.
if (choice == 5) {
laptop = "Razer Blade Stealth";
price = 1299.00;
} else {
if (choice == 4) {
laptop = "Alienware Area 51 -m";
price = 1999.99;
} else {
if (choice == 3) {
laptop = "Dell XPS 131";
price = 989.99;
} else {
if (choice == 2) {
laptop = "Asus zenbook 13 UX33FA";
price = 849.99;
} else {
if (choice == 1) {
laptop = "HP Envy 13";
price = 799.99;
} else {
System.out.printf("%nInvalid choice! Try again");
}
}
}
}
}
if (choice > 0) {
if (choice < 6) {
System.out.printf("Enter the quantity for %s: ", laptop);
qty = input.nextInt();
lineItem = qty * price;
subtotal = subtotal + tax;
if (trigger == 1) {
orderSummary += String.format("%n%,-9d %-30s %9s %,17.2f", qty, laptop, " ", lineItem);
trigger = 0;
}//END if for $ sign.
else {
orderSummary += String.format("%n%,-9d %-30s %9s %,17.2f", qty, laptop, " ", lineItem);
}
}
}
//Empty call to nextLine()
input.nextLine();
System.out.printf("%nEnter 'Y' to add another laptop to your purchase or 'N' to exit: ");
char y = input.nextLine().charAt(0);
}//END while
Try this, since you didn't show the while block in full,
char y = 'Y';
while(y == 'Y' || y == 'y')
{
// do whatever you want...
// ..................
System.out.println("Enter Y to add another laptop to your purchase or any other char to exit: ");
y = input.next().charAt(0);
}
Ok, so I have created the following program. It is not yet complete but when the code comes to the end (y or n part) and the user decides to try again they don't get the option to enter a new bet it just uses the one entered from the first time.
(Please comment if you need help about understanding the code or thinking it might be hard for other people to understand)
import java.util.*;
public class Lab15 {
static Scanner kin = new Scanner(System.in);
public static void main(String[] args) {
double money = 1000;
System.out.println("Welcom To Craps You Start With 1000$!!!");
int play = 1; //variable to cancel whole loop
char yesNo; //if user wants to continue playing or not
while(money > 0 && play == 1) {
System.out.print("Please Enter The Amount You Want To Bet: ");
double bet = kin.nextDouble();
while((bet <= money || bet > 0)) {
do { //loop to test if the bet is legit
if(money < bet || bet < 0) {
System.out.print("Sorry Invalid Bet; Please Enter A Legitimant Bet: ");
bet = kin.nextDouble();
}
} while(bet > money || bet < 0);
money -= bet;
System.out.println("You Have Bet $" + bet + " And Have " + money + " Left");
int die1 = (1 + (int) (6 * Math.random()));
int die2 = (1 + (int) (3 * Math.random()));
int sum = die1 + die2;
System.out.println("You Rolled " + die1 + " and " + die2 + " totaling " + sum);
System.out.print("Do You Want To Play Again(y) Or Not(n)");
yesNo = kin.next().charAt(0);
int loopBreak = 0; //to break do while loop bellow
do {
if(yesNo == 'y') { //take above yes no to restart loop or not
System.out.println("Restarting...");
loopBreak += 1;
continue;
}
else if(yesNo == 'n') {
System.out.println("Thank You For Playing");
play -= 1; //to cancel whole program
break;
}
else {
System.out.println("Please Enter 'y' Or 'n'");
}
} while(loopBreak == 0);
if(play == 0) {
break;
}
}
}
}
}
Its all about nested while loop don't stop when it needed. Its like this
while(money > 0 && play == 1) {
System.out.print("Please Enter The Amount You Want To Bet: ");
double bet = kin.nextDouble();
while((bet <= money || bet > 0)) {
...
do {
if(yesNo == 'y') { //take above yes no to restart loop or not
System.out.println("Restarting...");
loopBreak += 1;
continue;
}
else if(yesNo == 'n') {
System.out.println("Thank You For Playing");
play -= 1; //to cancel whole program
break;
}
else {
System.out.println("Please Enter 'y' Or 'n'");
}
} while(loopBreak == 0);
if(play == 0) {
break;
}
}
}
After you get answer 'y' you don't break the nested while and program never get the
while(money > 0 && play == 1) {
--> System.out.print("Please Enter The Amount You Want To Bet: ");
--> double bet = kin.nextDouble();
//because below while loop continues to loop
while((bet <= money || bet > 0)) {
...
}
}
part. Anyways corrected code is here(i tried every possibility and it worked)
import java.util.*;
public class Lab15 {
static Scanner kin = new Scanner(System.in);
public static void main(String[] args) {
double money = 1000;
System.out.println("Welcom To Craps You Start With 1000$!!!");
int play = 1; //variable to cancel whole loop
char yesNo; //if user wants to continue playing or not
while(money > 0 && play == 1) {
System.out.print("Please Enter The Amount You Want To Bet: ");
double bet = kin.nextDouble();
while((bet <= money || bet > 0)) {
do { //loop to test if the bet is legit
if(money < bet || bet < 0) {
System.out.print("Sorry Invalid Bet; Please Enter A Legitimant Bet: ");
bet = kin.nextDouble();
}
} while(bet > money || bet < 0);
money -= bet;
System.out.println("You Have Bet $" + bet + " And Have " + money + " Left");
int die1 = (1 + (int) (6 * Math.random()));
int die2 = (1 + (int) (3 * Math.random()));
int sum = die1 + die2;
System.out.println("You Rolled " + die1 + " and " + die2 + " totaling " + sum);
System.out.print("Do You Want To Play Again(y) Or Not(n): ");
yesNo = kin.next().charAt(0);
int loopBreak = 0; //to break do while loop bellow
do {
if(yesNo == 'y') { //take above yes no to restart loop or not
System.out.println("Restarting...");
loopBreak++;
continue;
}
else if(yesNo == 'n') {
System.out.println("Thank You For Playing");
play--; //to cancel whole program
break;
}
else {
System.out.println("Please Enter 'y' Or 'n': ");
}
} while(loopBreak == 0);
if(play == 0 || loopBreak == 1) {
break;
}
}
}
}
}
Have a good day!
Another solution is to use labeled breaks/continues https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
However it should be used sparingly (or not at all). You probably can simplify it in some other way.
package test.test;
import java.util.Scanner;
public class Lab15 {
static Scanner kin = new Scanner(System.in);
public static void main(String[] args) {
double money = 1000;
System.out.println("Welcom To Craps You Start With 1000$!!!");
int play = 1; // variable to cancel whole loop
char yesNo; // if user wants to continue playing or not
//Labeled <-----------------
start: while (money > 0 && play == 1) {
System.out.print("Please Enter The Amount You Want To Bet: ");
double bet = kin.nextDouble();
while ((bet <= money || bet > 0)) {
do { // loop to test if the bet is legit
if (money < bet || bet < 0) {
System.out.print("Sorry Invalid Bet; Please Enter A Legitimant Bet: ");
bet = kin.nextDouble();
}
} while (bet > money || bet < 0);
money -= bet;
System.out.println("You Have Bet $" + bet + " And Have " + money + " Left");
int die1 = (1 + (int) (6 * Math.random()));
int die2 = (1 + (int) (3 * Math.random()));
int sum = die1 + die2;
System.out.println("You Rolled " + die1 + " and " + die2 + " totaling " + sum);
System.out.print("Do You Want To Play Again(y) Or Not(n)");
yesNo = kin.next().charAt(0);
int loopBreak = 0; // to break do while loop bellow
do {
if (yesNo == 'y') { // take above yes no to restart loop or not
System.out.println("Restarting...");
loopBreak += 1;
//Labeled continue <-----------------
continue start;
} else if (yesNo == 'n') {
System.out.println("Thank You For Playing");
play -= 1; // to cancel whole program
break;
} else {
System.out.println("Please Enter 'y' Or 'n'");
}
} while (loopBreak == 0);
if (play == 0) {
break;
}
}
}
}
}
I've recently decided that I want to make a program that plays a game called "Nim," which is a game in which you start with a predetermined amount of "sticks" and each player takes turns removing between 1 and 3 sticks. Whoever removes the last stick loses.
Anyway, I have written my program and it compiles and runs almost flawlessly. There's only one small problem. After the game is over, it shows the "good game" screen twice, with the game's very first line appearing in the middle (I'll post screenshots at the end here). It's very strange, and I was just wondering if you guys could give it a look.
I'm cutting a chunk of the program out (only one class, named Cup()), because it's somewhat long, so if you see a class you don't recognize then just ignore it. It's pretty self explanatory what the class does in the program, and it's not where the error is occurring. Here's the code.
class SticksGame
{
public static void main(String[] args) throws InputMismatchException
{
Random r = new Random();
int score1 = 0, score2 = 0;
Cup c = new Cup();
int j = 0, d = 0, i = 0, k = 0;
boolean b = true;
String exit = "default";
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the Sticks Game! Last Stick loses! Must pick 1 - 3 sticks.");
System.out.println();
do
{
i = r.nextInt(15) + 9;
System.out.println("We begin with " + i + " sticks");
System.out.println();
while (b == true)
{
System.out.println("Your move");
k = input.nextInt();
if (k > 3)
{
System.out.println("You must select between 1 and 3 sticks");
k = input.nextInt();
}
else if (k < 1)
{
System.out.println("You must select between 1 and 3 sticks");
k = input.nextInt();
}
else
{
j = i;
i = i - k;
if (i <= 0)
{
System.out.println("Computer wins!");
score2 = (score2 + 1);
b = false;
}
else
{
System.out.println("We now have " + i + " sticks.");
}
d = c.select();
System.out.println("Computer removes " + d + " sticks");
i = i - d;
System.out.println("We now have " + i + " sticks");
if (i <= 0)
{
System.out.println("You Win!");
score1 = (score1 + 1);
b = false;
}
}
}
System.out.println();
System.out.println("Good game!");
System.out.println("Your score: " + score1 + " Computer's Score: " + score2);
System.out.println("Press enter if you'd like to play again. Otherwise, type \"quit\"");
exit = input.nextLine();
b = true;
}
while(!"quit".equals(exit));
}
}
Any helps are appreciated! Thanks :)
~Andrew
CODE EDITED FOR JANOS
A little late, I know, but here is the FULL GAME for anyone who wants to play! feel free to copy and paste it into your notepad and execute using cmd(YOU MUST KEEP MY NAME AS A COMMENT ON TOP!) :)
//Andrew Mancinelli: 2015
import java.util.*;
import java.io.*;
class Cup
{
private ArrayList<Integer> c = new ArrayList<Integer>();
public Cup()
{
c.add(1);
c.add(2);
c.add(3);
}
public int count()
{
return c.size();
}
public int select()
{
int index = (int)(c.size() * Math.random());
return c.get(index);
}
public void remove(Integer move)
{
c.remove(move);
}
}
class SticksGame
{
public static void help()
{
System.out.println();
System.out.println("Okay, so here's how it works... The object of the game is to NOT have the last stick. Whoever ends up with the very last stick loses.");
System.out.println();
System.out.println("Rule 1: You will each take turns removing sticks. you may only remove 1, 2, or 3 sticks in a turn");
System.out.println();
System.out.println("Rule 2: The beginning number of sticks is always random between 9 and 24 sticks");
System.out.println();
System.out.println("Rule 3: Whoever chooses the last stick, LOSES!");
System.out.println();
System.out.println("And that's it! Simple, right?");
}
public static void main(String[] args) throws InputMismatchException
{
Random r = new Random();
int score1 = 0, score2 = 0;
Cup c = new Cup();
int j = 0, d = 0, i = 0, k = 0;
boolean b = true;
String exit = "default", inst = "default";
Scanner input = new Scanner(System.in);
System.out.println("Welcome to the Sticks Game! Last Stick loses!");
System.out.println();
System.out.println("Need some instructions? Type \"help\" now to see the instructions. Otherwise, press enter to play!");
inst = input.nextLine();
if (inst.equals("help"))
{
help();
System.out.println();
System.out.println("press \"enter\" to begin!");
inst = input.nextLine();
}
do
{
i = r.nextInt(15) + 9;
System.out.println();
System.out.println("We begin with " + i + " sticks");
System.out.println();
while (b == true)
{
System.out.println("Your move");
k = input.nextInt();
if (k > 3)
{
System.out.println("You must select between 1 and 3 sticks");
k = input.nextInt();
}
else if (k < 1)
{
System.out.println("You must select between 1 and 3 sticks");
k = input.nextInt();
}
else
{
j = i;
i = i - k;
if (i <= 0)
{
System.out.println("Computer wins!");
score2 = (score2 + 1);
b = false;
break;
}
else
{
System.out.println("We now have " + i + " sticks.");
}
d = c.select();
i = i - d;
if (i >= 0)
{
System.out.println("Computer removes " + d + " sticks");
System.out.println("We now have " + i + " sticks");
}
if (i <= 0)
{
System.out.println("You Win!");
score1 = (score1 + 1);
b = false;
break;
}
}
}
System.out.println();
System.out.println("Good game!");
System.out.println("Your score: " + score1 + " Computer's Score: " + score2);
System.out.println("Press enter if you'd like to play again. Otherwise, type \"quit\"");
input.nextLine();
exit = input.nextLine();
b = true;
}
while(!"quit".equals(exit));
}
}
The problem is that this condition is always true:
while (exit != "quit");
Because != means "not identical",
and the exit variable and "quit" are not identical.
Use the equals method for checking logical equality.
In this example, change the loop condition to this instead:
while (!"quit".equals(exit));
For your other problem of not properly starting a second game,
you need to reinitialize the state variables,
for example reset b = true.
Lastly, note that input.nextInt() doesn't read the newline character that you pressed when entering a number. So when exit = input.nextLine() runs, it reads that newline character, and doesn't actually give you a chance to type "quit". To solve this, add input.nextLine(); right before exit = input.nextLine();
The unexpected retry was because of the use of input.nextLine(); the program assumed that you already pressed [enter].
From previous work, the two options is to insert one more input.nextline();
input.nextLine();
exit = input.nextLine();
Or use input.next(); instead, although enter will not work for this method so you may need to enter any key or "quit" to exit;
exit = input.next();
I can't make this program show the message "Number out of range" when the user put a number out of (1 - 6). I tried different ways of code, but I don't know what I am doing wrong.
public static void main(String[] args) {
int guess = 0;
int tries = 3;
Scanner input = new Scanner(System.in);
Random ran = new Random();
int diceNumber = ran.nextInt(6)+1;
System.out.println(diceNumber);
System.out.println("Insert a number between 1 and 6 : you have " + tries + " tries.");
guess = input.nextInt();
while((tries >1 && (guess <7 || guess>0))) {
tries--;
System.out.println("Incorrect Number, you have " +tries+ " more tries.");
guess = input.nextInt();
}if(guess >=7 || guess<=0 && (tries >1)){
--tries;
System.out.println("Number out of range, try again; you have " + tries + " more tries.");
guess = input.nextInt();
} if(tries ==0 || guess != diceNumber) {
System.out.println("You Lose!!");
} else if(guess == diceNumber){
System.out.println("You Win!!");
}
}
You need to position the condition to check if the input is a valid input or not at the start of the while loop , currently, it will only be checked after all tries are exhausted as you end the while loop before it.
Also, you should change the while loop condition from (tries >1 && (guess <7 || guess>0)) to (tries > 1 && guess != diceNumber) , since you may not want to exit the loop if the number entered is outside the range.
Code -
public static void main(String[] args) {
int guess = 0;
int tries = 3;
Scanner input = new Scanner(System.in);
Random ran = new Random();
int diceNumber = ran.nextInt(6)+1;
System.out.println(diceNumber);
System.out.println("Insert a number between 1 and 6 : you have " + tries + " tries.");
guess = input.nextInt();
while((tries >1 && guess != diceNumber)) {
if((guess >=7 || guess<=0) && (tries >1)){
--tries;
System.out.println("Number out of range, try again; you have " + tries + " more tries.");
guess = input.nextInt();
}
else {
tries--;
System.out.println("Incorrect Number, you have " +tries+ " more tries.");
guess = input.nextInt();
}
}
if(tries ==0 || guess != diceNumber) {
System.out.println("You Lose!!");
} else if(guess == diceNumber){
System.out.println("You Win!!");
}
}
The below code will fetch you the expected result.
import java.util.Random;
import java.util.Scanner;
public class Dice {
public static void main(String[] args) {
int guess = 0;
int tries = 3;
Scanner input = new Scanner(System.in);
Random ran = new Random();
int diceNumber = ran.nextInt(6) + 1;
System.out.println(diceNumber);
System.out.println("Insert a number between 1 and 6 : you have "
+ tries + " tries.");
guess = input.nextInt();
loop: while ((tries >= 1)) {
--tries;
if ((guess >= 7 || guess <= 0) && (tries >= 1)) {
System.out.println("Number out of range, try again; you have "
+ tries + " more tries.");
guess = input.nextInt();
} else {
if (guess == diceNumber) {
System.out.println("You Win!!");
break loop;
} else if (tries >= 1) {
System.out.println("Incorrect Number, you have " + tries
+ " more tries.");
guess = input.nextInt();
}
}
}
if (tries == 0 && guess != diceNumber) {
System.out.println("You Lose!!");
}
}
}
I think the problem is in your while loop.
I'd say it should be something like this:
while(tries > 0 && guess != diceNumber) {
tries--;
if (guess >= 1 && guess <= 6) {
System.out.println("Incorrect Number, you have " +tries+ " more tries.");
} else if (guess >=7 || guess<=0) {
System.out.println("Number out of range, try again; you have " + tries + " more tries.");
}
if (tries > 0) {
guess = input.nextInt();
}
}
if(tries == 0 || guess != diceNumber) {
System.out.println("You Lose!!");
} else if(guess == diceNumber){
System.out.println("You Win!!");
}
I think this should do what you want.
As you can see, I changed the while condition:
You want the user to be able to enter another number while he has at least 1 try left, so tries>0.
You want the user to enter another number only if guess != diceNumber.
The if conditions inside also change:
You only say it's an incorrect number if the entered number is between 1 and 6: guess >= 1 && guess <= 6.
You only say it's out of range if the number is not between 1 and 6: guess >= 7 || guess <= 0.
You don't need to check the number of tries, the while loop does that already.
You only want to get a new input number if the user as a try left: tries > 0.
I am trying to run the while loop below for my Programming I class extra credit. It's supposed to simulate a game of craps however I can't figure out why the bottom while loop runs no matter what.
import java.util.Random;
import java.util.Scanner;
public class ExtraCredit {
public static void main(String[] args)
{
Scanner scan = new Scanner( System.in );
Random random = new Random( );
int die1, die2, roll;
int dice = 0;
int point = 0;
int finish = 0;
int play = 1;
while (play == 1)
{
System.out.println ("Enter 0 to roll the dice");
roll = scan.nextInt( );
if (roll == 0)
{
die1 = random.nextInt( 6 ) + 1;
die2 = random.nextInt( 6 ) + 1;
dice = die1+die2;
}
if (dice == 7 || dice == 11)
{
System.out.println ("\nYou rolled a " + dice + " on your first roll!");
System.out.println ("You win!");
finish = 1;
}
else if (dice == 2 || dice == 3 || dice == 12)
{
System.out.println ("You rolled a " + dice + " on your first roll!");
System.out.println ("You lose!");
finish = 1;
}
else
{
point = dice;
System.out.println ("\nYour point is " + point);
System.out.println ("You need to roll a " + point + " to win");
System.out.println ("Enter 0 to Roll again");
roll = scan.nextInt( );
if (roll == 0)
{
die1 = random.nextInt( 6 ) + 1;
die2 = random.nextInt( 6 ) + 1;
dice = die1+die2;
}
}
while (dice != point || dice != 7 || finish != 1)
{
System.out.println ("\nYou rolled a " + dice);
System.out.println ("Roll again");
roll = scan.nextInt( );
if (roll == 0)
{
die1 = random.nextInt( 6 ) + 1;
die2 = random.nextInt( 6 ) + 1;
dice = die1+die2;
}
}
if (dice == point)
{
System.out.println ("\nYou rolled your point (" + point +")");
System.out.println ("You won!");
}
if (dice == 7)
{
System.out.println ("\nYou rolled a 7 before you could match your point");
System.out.println ("You Lose!");
}
System.out.println ("\nEnter 1 to play again");
play = scan.nextInt( );
}
}
}
(dice != point || dice != 7 || finish != 1)
This will never be false.
Try this
(dice != point && dice != 7 && finish != 1)
You want to change the ||'s to &&'s
while (dice != point && dice != 7 && finish != 1)