Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Dice Game (class,enum,interface expected error) Posted by FLDancingQueen on 14 Oct 2012 at 5:27 AM
Hey y'all, so I needed to create a dice game that wins when there's a pair, but gives the user the option to continue or quit if they don't roll a pair. Please see code below and any assistance is greatly appreciated. The errors are showing in lines 7, 8, 9. Thankies!!
~FLDancingQueen

/*Introduction to Problem Solving and Algorithm Design, Project #4, Nathalie */
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Random;


int numRolls = 0;//number of rolls
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2= new Random().nextInt(6)+1;

public class DiceGame {//Game Program



public static void main(String[] args) {//Main Module



out.println(" ************ ");
out.println(" Try your luck and roll a pair!! ");
out.println(" ************ ");
out.println();


out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;

while (randomNumber1!=randomNumber2){//while dice don't match give the option
int choice;
out.println("Would you like to try again? Press '1' to Continue or '2' to End");
out.println(" ");//Just wanted a space here
Scanner keyboard=new Scanner(System.in);

switch(choice) {//choice to keep rolling start
case 1:
int randomNumber1 = new Random().nextInt(6)+1;
int randomNumber2=new Random().nextInt(6)+1;
out.println("You rolled a " +randomNumber1+ " and a "+randomNumber2);
numRolls++;

case 2:
out.print("You chose to end the game without winning after");
out.println(numRolls + " tries.");
}//choice to keep rolling end

}//while dice don't match END


out.print("You won after");
out.println(numRolls + " rolls!");



}//Ends Main Module
}//Ends Game Program




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.