Hi
i don't know if anyone can help me or not??

i have an assignment about java dice game and here is the instructions:

This program will simulate two people playing a two dice game. The objective of this game is to be the first to score 100 points. The two players take turns to roll two dice following these rules:
1. If the number one does not appear in either of the dice, the player adds the two dice values to his/her score and the turn passes to the next player.
2.If the number one appears in one die, nothing is added and the turn passes to the next player.
3.If the number one appears in both dice then the player loses all the accumulated points and the turn.

thnks

What have you done so far? Which part of the code you already have, and which part do you have trouble with?

hi
thanks for the replay
i just started a course and i am at the very begining of java knowledge, so far i have done only this, and i'm not sure if it correct or not )":
can you help please??

package dise1;
import java.util.Scanner;
public class Dise1 {

       public static void main(String[] args) {
         System.out.println("please throw the dise?");
       int dice;
       Scanner kb = new Scanner(System.in);
       dice = kb.nextInt();
       if (dice >1){
       int number;
       number = (int)(Math.random()*6+1);
       System.out.println("you got"+number);
    }



    }
}

The code you wrote means that one dice is thrown, and the player decides the number that is shown on the dice - I doubt that this is what you want.
In order to generate a random number between 1-6, take a look at the Random class. You can create a random number between 0 to n-1 by using the nextInt(int n) method, therefore in order to create a dice throw, meaning a random number between 1 to 6, you can use the following code:

import java.util.Random;
Random rnd = new Random();
int dice1 = Random.nextInt(6) + 1; //Random.nextInt(6) will produce a random number in the range of 0-5

Try to implement this in your code, and try to build the generator so the user will get to throw two dice, with random number on each dice each turn.

Good luck, and if you still encounter problems post the code that you have done so far and I'll try to guide you.

hi

i am really trying to do this java game but as i am very new in java i couldn't even use the cod you gave me

can anyone please help me to finish this game????????????

Can you post what you have done so far?

hi
i only did this

package dise1;
import java.util.Scanner;
public class Dise1 {

public static void main(String[] args) {
System.out.println("please throw the dise?");
int dice;
Scanner kb = new Scanner(System.in);
dice = kb.nextInt();
if (dice >1){
int number;
number = (int)(Math.random()*6+1);
System.out.println("you got"+number);
}

}
}

but i think this is wrong

can you halp me

As apines just said, try implementing his suggestion in your code.

hi

i have done this dice game but i need UML digrame for the game can anyone help me??
thanks

Sure, what have you done so far? Can you post your current diagram?

to be honest i have no idea how to start it

I guess that this place is good as any :) Read the tutorial, try to sketch a draft, and if you encounter any problems post it here and we'll help you.

thanks for the help

i've done the diagram but i am not sure about it??
i would like u please to have a look and tell me what is wrong, or what is missing??

but first can u help me upload the file? i don't know why is not working??

thanks

  1. Go to the advance editor.
  2. Under "Additional Options" press on the "Manage Attachments" button
  3. Choose the file that you want to upload
  4. Press the "Upload" button
  5. You are done.

this is the diagram

hi
i have a question

in this dice game programm i have 3 classes and the question is that,

should the result of the 3 classes be the same, i mean after you run the programm?? or each class has different result??

thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.