Results 1 to 2 of 2
  1. #1
    daftwolfie is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Need help with a dice program. Thanks!!

    Hi all!,
    I'm pretty new to this forum and I hope I can get some help with my java codes. I'm a noob as I've just started java lessons in school, my 4th lesson already. I have this assignment in which I have to create a Snake and Ladder game. I have to create a dice program and I need help with inserting a loop. This is what I have so far:

    Java Code:
    import java.io.IOException;
    import java.util.Random;
    
    public class Dice {
    	public static void main(String[] args) {
    
    		Random generator = new Random();
    		// dice array.
    		int [] frequency = new int [6];
    
    		frequency[0] = 1;
    		frequency[1] = 2;
    		frequency[2] = 3;
    		frequency[3] = 4;
    		frequency[4] = 5;
    		frequency[5] = 6;         
    
    		//use [ENTER] to continue.
    		System.out.println("Please Press Enter To Roll Dice >  ");
    		try{
    			System.in.read();
    			while (System.in.available() > 0)
    				System.in.read(); 
    		}
    		catch (IOException e){
    			e.printStackTrace();
    		}
    
    		// Need a loop over here, so that they will ask again if the dice shows 6.
    		int i = generator.nextInt(6);
    		int numberShows = frequency[i];
    		System.out.println("Dice Turns Up >  "+ numberShows);
    
    		if 	(numberShows == 6){
    			System.out.println("Dice shows six, you get more more turn!");
    		}
    		else{
    			System.out.println("End Of Turn");
    		}
    	}
    }
    Attached Files Attached Files
    Last edited by daftwolfie; 05-15-2011 at 10:33 AM. Reason: Thanks sunde887 =)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Would you mind posting your code directly instead of as an attachment? To do this, type [code] then paste your code and finally add this tag at the end of your code[/code]

Similar Threads

  1. Kindly Help me..DICE PROGRAM
    By aronkevin in forum Advanced Java
    Replies: 1
    Last Post: 10-08-2010, 07:32 AM
  2. Please help..dice java program
    By aronkevin in forum New To Java
    Replies: 3
    Last Post: 10-08-2010, 05:37 AM
  3. Dice Simulation Program
    By touandcim in forum New To Java
    Replies: 3
    Last Post: 03-15-2010, 12:09 PM
  4. Java Program (rolling the dice)
    By genocist in forum New To Java
    Replies: 8
    Last Post: 03-01-2010, 03:15 PM
  5. Small Dice Program
    By kimmelim in forum New To Java
    Replies: 13
    Last Post: 02-15-2009, 01:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •