DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005

    Need project help

    Hey guys. I'm in a Java class and I have NO CLUE what I am doing. I have a project that is a Dice Simulator. We have to write a program that simulates User-specified number of rolls and then prints a histogram of the number of rolls for each pair value, i.e. the number of times a 2 was thrown, 3 was thrown, etc. We have to use a frequency array. I do not understand how to do this. Can someone please help me. I mean, I also had to do a driver class which I have some of it completed not all, so if you need me to post that I can. I'm still working on that part of it but I am figuring it out slowly. However, I am completely at a loss on this other part. Any help/advice would be greatly appreciated.

  2. #2
    Join Date
    Aug 2003
    A frequency array is simply going to be an array where the index is the value and the value stored at the index is the number of times that value has occured. For instance,
    int[] frequencies = new int[6];
    frequencies[0]; // represents the number of times a 1 was rolled
    frequencies[1]; // represents the number of times a 2 was rolled
    frequencies[2]; // represents the number of times a 3 was rolled
    So, in your program when you roll a number you do something like this:
    int rollValue = Die.roll(); // or however you are getting the value fo the roll
    frequencies[rollValue-1]++; // increment the number of times that the value showed up.
    Hope this helps.

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. Good Editorial by Russell Jones
    By Robert G in forum .NET
    Replies: 84
    Last Post: 02-08-2001, 02:38 PM
  3. Replies: 0
    Last Post: 09-13-2000, 10:18 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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.