Results 1 to 2 of 2

Thread: dice program

  1. #1
    devindadude is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default dice program

    Hi, I having a problem with my dice program that will roll one dice to count the amount of times a certain face will appear and I can only use math.random, I wrote the code but it is not working properly and don't understand why if anyone could help me out I would greatly appreciate it. Here is the code:

    import java.util.*;

    /* Name: Devin Johnson
    * Teacher: Dr. Sung
    * Class: CMSC 3103
    * Due: Feb. 6, 2013
    * Description: This program will ask the user to enter how many times to
    * roll a dice. The program will then display the results for each number
    * of the faces on the die. There are 2 classes, MyDice class will remember the
    * dice rolling and command to roll the dice. Quiz05 will ask for entry and
    * will display the information.
    */
    public class Quiz05 {

    public static void main(String[] args){

    Scanner input = new Scanner(System.in);
    boolean valid = true;
    MyDice dice = new MyDice();

    while(true){

    System.out.print("Please enter a number for roles (greater than 1000):");
    int value = input.nextInt();
    if(value < 1000 || value > 100000){
    System.out.println("Entry is not valid, please try again!");
    continue;
    }

    for(int i = 1; i <= value; i++){
    dice.roll();
    }
    System.out.printf("The dice was rolled %d times\n", value);
    System.out.printf("the number of 1s = %5.1f\n",dice.getOne());
    System.out.printf("the number of 2s = %5.1f\n",dice.getTwo());
    System.out.printf("the number of 3s = %5.1f\n",dice.getThree());
    System.out.printf("the number of 4s = %5.1f\n",dice.getFour());
    System.out.printf("the number of 5s = %5.1f\n",dice.getFive());
    System.out.printf("the number of 6s = %5.1f\n",dice.getSix());

    }
    }
    }


    import java.util.*;


    public class MyDice {

    private double one;
    private double two;
    private double three;
    private double four;
    private double five;
    private double six;
    private int die;




    public void roll(){

    die = (int)(Math.random()*6) + 1;
    if(die == 1){
    this.one = ++one;
    }
    if(die == 2){
    this.two = ++two;
    }
    if(die == 3){
    this.three = ++three;
    }
    if(die == 4){
    this.four = ++four;
    }
    if(die == 5){
    this.five = ++five;
    }
    if(die == 6){
    this.six = ++six;
    }
    }

    public double getDie() {
    return die;
    }

    public double getOne() {
    return one;
    }

    public double getTwo() {
    return two;
    }

    public double getThree() {
    return three;
    }

    public double getFour() {
    return four;
    }

    public double getFive() {
    return five;
    }

    public double getSix() {
    return six;
    }

    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: dice program

    Do you think Dr Sung or UCO will approve you asking here?

    That aside, use [code] tags when posting code and what exactly isn't working? Compiler errors? Runtime exceptions? What output do you get? What do you expect?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Need Help with Dice Program
    By Valerie1067 in forum New To Java
    Replies: 3
    Last Post: 05-04-2012, 06:37 AM
  2. Dice Program
    By rahulkumarnaik in forum New To Java
    Replies: 14
    Last Post: 11-15-2011, 08:05 PM
  3. Need help with a dice program. Thanks!!
    By daftwolfie in forum Eclipse
    Replies: 1
    Last Post: 05-15-2011, 11:28 AM
  4. Kindly Help me..DICE PROGRAM
    By aronkevin in forum Advanced Java
    Replies: 1
    Last Post: 10-08-2010, 08:32 AM
  5. Small Dice Program
    By kimmelim in forum New To Java
    Replies: 13
    Last Post: 02-15-2009, 02: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
  •