Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 8th, 2005, 7:48 PM   #1
Keldor
Newbie
 
Keldor's Avatar
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 Keldor is on a distinguished road
Exclamation Simply Comlicated(RollDie)

Ok being as I am new to this forum, and to java itself, I am seeking help form someone hwo is willing to solve my simple(to you) but complicated(for me) task of completeing my RollDie array program. I so farr have this array, which works and everything, ie. displays the output and the number of times each face of the die came up, but my modification which I cannot seem to get to work is a trap for the very first roll, the program should display the first roll(side 1 or 2or 3 etc...), and then the number of times each side came up etc...after which it will check the first rolled side against all the rolled sides, where upon if the first rolled side is not equal to the side with the most hits, a statment will output declaring false, otherwise if it does match up the output would be true. Much thanks are indebted to anyone who can help me with this program.



[code]
import javax.swing.*;

public class RollDie
{
public static void main(String[] args)
{
int numFlips = 100;
int randNum;
int frequency[] = new int[7];

for (int flip = 1; flip <= numFlips; flip++)
{
randNum = 1 + (int)(Math.random() * 6);
frequency[randNum]++;
}

String output = "Face:\tFrequency:\n";

for(int face = 1; face < frequency.length; face ++)
{
output += "\n" + face + "\t" + frequency[face];
}

JTextArea outputArea = new JTextArea();
outputArea.setText(output);
JOptionPane.showMessageDialog(null, outputArea,
"Rolling a Die",
JOptionPane.WARNING_MESSAGE);

System.exit(0);
}
}
[\CODE]
Keldor is offline   Reply With Quote
Old Feb 8th, 2005, 8:30 PM   #2
EdSalamander
Programmer
 
EdSalamander's Avatar
 
Join Date: Dec 2004
Location: Tucson, AZ, USA
Posts: 80
Rep Power: 4 EdSalamander is on a distinguished road
Send a message via AIM to EdSalamander
Instead of checking agianst each one each time, I'd add another variable that keeps track of the most frequent die roll. Also, every time the frequency of a face increases, check that new frequency against the highest to see if it's taken the lead. As for the rest, what do you mean "a statement will output?" To the console? To your GUI? And what do you mean by "the first roll?" After just the first roll, there won't be any data yet to compare it too or display. What's your overall objective, to prevent a number from being roled if it's already the most frequent?
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose?
EdSalamander is offline   Reply With Quote
Old Feb 9th, 2005, 7:14 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
Also in the true nature of OO approach instead of having class roll die, make the die an object with a roll function in it. Thenyou only have to call the function each time (saves on code in some senes )
Berto is offline   Reply With Quote
Old Feb 9th, 2005, 3:05 PM   #4
Keldor
Newbie
 
Keldor's Avatar
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 Keldor is on a distinguished road
Ed your reply has helped me so much, thanks
Keldor is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC