Solved

Code help! thanks

Posted on 2004-04-22
5
267 Views
Last Modified: 2010-03-31
Hi,

I'm new to java, I'm taking a class now but I'm totally lost in the class.. I'm really struggling.. and am in seek of some assistance.. The teacher has assigned a project and I do not know where to start.. I'm new to this forum so please forgive me if I break any rules for posting..

Any ways the project that was assigned to me is due tommorrow.. and I forgot about it till now..So any help would be greatly appricated...

Heres the project:

simulating throwing a die and counts the frequency of each possible outcome: 1 though 6...and also compute the ratio of each outcome occurrences divided by the total of throwings


Again thanks for your help !
0
Comment
Question by:aCCeSSgRanteD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Expert Comment

by:seanrowen
ID: 10892330
I'm sure nobody here wants to give too much away since this is a homework problem, but I imagine you know that you will need to simulate the die throw by generating some random numbers, and collect some statistics on the outcomes. Look at java.util.Random to start, and its nextInt(int n) method.
0
 
LVL 2

Author Comment

by:aCCeSSgRanteD
ID: 10892455
Actually, I was looking into this for a friend.. he was on a deadline and ask if I could help him.  Unfortunately, I dont do any programming with java.  I was looking ay maybe getting some code to help him get started..

Thanks for your suggestion.. and I will pass on the things you ask for him to check..

thanks!
0
 
LVL 2

Author Comment

by:aCCeSSgRanteD
ID: 10892551
If anyone has the time..

the assignment is posted..

http://hal.lamar.edu/~licc/COSC1373/

#7

thanks

ps.. I'm no person to ask for a handout but my forte is not java..

thanks again for anyhelp
0
 
LVL 1

Accepted Solution

by:
derkec earned 50 total points
ID: 10892970
Let us know where you get stuck. It's going to look something like:

...

int numberToThrow = 100;
Random rand = new Random();
int[] count = {0,0,0,0,0,0};

for(int i = 0; i < numberToThrow; i++) {
    nextRoll = rand.nextInt[6]; // number 0-5 which we pretend is 1-6
    count[i]++;
}
System.out.println("Number of times 1 was thrown: " + count[0]);
System.out.println("Number of times 2 was thrown: " + count[1]);
.....
System.out.println("Percentage of times 1 was thrown: " + count[0]/numberToThrow);
...


0
 
LVL 2

Author Comment

by:aCCeSSgRanteD
ID: 10931475
I dont know if this helped my friend out or not.. but I gave it to him.. and havent heard of him .. soo i guess it works..

anyhoot.. thanks for the help..

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
by zero exception 10 69
Java: How do I open the default windows program for a given file type 3 53
Print Rhino Java Array in Javascript 1 34
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question