Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Dice game code creating help!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Dice game code creating help!

    Hello! Evryone im not really good at java programming so i hope you dont mind with some silly questions!
    So i have to create a java code which imitates dice rollings till rolls up 1 or 6 when comes 1 or 6 the game stops and counts everything togeather. So here is my idea how to create a code but it isnt working well, especially part when have to count everything!

    Thanks everyone!


    import java.util.Random; //java iebuvets nejausi izveletu skaitlju generators

    class kaulins {
    public static void main (String[] args) {
    Random kaulinss = new Random();
    int skaitlis;


    System.out.println("Speles noteikumi - Jus metat kaulinju tik ilgi lidz uzmetat");
    System.out.println("viens vai sesi, kad ir uzmests kads no siem skaitliem spele");
    System.out.println("beidzas un jus iegustat savu rezultatu, jo lielaks rezultats");
    System.out.println("jo labak jums!");

    System.out.println("Lai spele sakas!!!");

    for(int counter=1; counter<=20; counter++){
    skaitlis = 1+kaulinss.nextInt(6);
    System.out.println(skaitlis+" - metiena rezultats");



    if (skaitlis == 6)
    System.exit(0);
    else
    System.out.println("");

    if (skaitlis == 1)
    System.exit(0);
    else
    System.out.println ("");

    String sum;
    System.out.println(sum = skaitlis+skaitlis+"Rezultats kopaa!");


    }


    }
    }


    class rezultats extends kaulins {

    public static void main(String[] args) {

    String sum;
    System.out.println(sum = skaitlis+skaitlis + "Rezultats kopaa!");

    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Dice game code creating help!

    Is this question posted on other forums? Please provide a link here to the other forums.

    it isnt working well
    Please explain what is wrong.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Dice game code creating help!

    1. Use code tags.
    2. Read what System.exit(0) do. It kills the current process that means your application will be quit as soon as it will reach this statement and no further execution of any statement.

    And what are you trying to do with your code? Are these both classes include in your code or only the first one?
    You must study the very basics first.

  4. #4
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Stressed
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Dice game code creating help!

    Since you need the game to run until something specific happens (you roll a 1 or a 6), how about using a while loop?
    You can declare a variable to store the most recent dice roll, and base the while loop off from that. For counting everything that was rolled, keep track by adding this variable you created for most recent roll and add it to a variable for total rolls.

    Something like, totalRolls += mostRecent;

    Also, System.exit(0) ends your program, not just your dice game. You wont need that at all.
    You'll need to spend some time puzzling out the logic inside your while loop.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Dice game code creating help!

    Quote Originally Posted by Norm View Post
    Is this question posted on other forums?
    Yeah it looks suspiciously like this one: dice game code creating help!
    Improving the world one idiot at a time!

Similar Threads

  1. Help with creating a dice rolling program in Java
    By lilmiss in forum Object Oriented Programming
    Replies: 4
    Last Post: October 26th, 2011, 09:27 PM
  2. Dice Wagering Game new to Multiple Classes
    By Laxman2809 in forum What's Wrong With My Code?
    Replies: 24
    Last Post: September 16th, 2011, 08:22 PM
  3. Dice Game help and Arrays
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 9th, 2011, 10:08 PM
  4. Dice game help, a little cleanup
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 28th, 2011, 12:28 PM
  5. Help Creating a method for my jellyBean gussing game
    By CookiesForRandy in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 20th, 2010, 09:29 AM

Tags for this Thread