Java random die table generator! please Help ASAP!?
-
Write a game program that prints a chart to the screen showing the randomness of a dice. First the game prompts the user for a number of die throws he would like. The game then throws that die that many times. The game then prints a chart showing a line of asterisks for each die number, indicating the number of times the die landed with that face number of top. The chart should look different everytime it runs. A sample output: Enter the number of times you would like to throw the dice: 20 The chart showing 20 throws of the dice: 1 **** 2 **** 3 ** 4 *** 5 ***** 6 ** Heres what i have so far: System.out.println("Please enter the number of times that"); System.out.println("you would like to throw the dice: "); Scanner input = new Scanner (System.in); numberOfTimes = input.nextInt(); System.out.println("The chart showing " + numberOfTimes + " throws of the dice:"); while(dieResults >= numberOfTimes) //here im telling it that the number of throws cannot be more than the number the user told it. { dieResults = (int)(6.0*Math.random()) +1; //get random number dieResults++; //keepts getting random numbers until while condition met. System.out.println(dieResults); //print out results. } Now, how do i make the chart and put an asterisks for each times its one of the numbers. I was thinking that maybe its a lot of If statements. For example If diesults == 1 then system.out.println ("*"); i tried that but it doesn't work. so can someone please help not only write the code for me but explain each step. And it needs to use the math.random() and not import a random number generator AND ALSO, no using arrays and its supposedly supposed to have a lot of if then statements, for example if the out put equals 1 then the "*" appear.
-
Answer:
System.out.println("Please enter the number of times that"); System.out.println("you would like to throw the dice: "); Scanner input = new Scanner (System.in); numberOfTimes = input.nextInt(); System.out.println("The chart showing " + numberOfTimes + " throws of the dice:"); As we want how many times 1 is thrown, 2 is thrown, better you take an array having six elements int count[]={0,0,0,0,0,0}; for(int i=0;i<numberOfTimes;i++) { dieResults = (int)(6.0*Math.random()) +1; //get random number count[dieResults]++; //increments the count value } You decide at most how many *'s are needed. Rather you have to normalize this data such that smallest value to be have 1 and highest value to be maximum number of *'s needed by you. I am not doing this normalization. You can do on your own. for(i int i=0;i<6;i++) { for(int j=0;j<count[i];j++) System.out.print("*"); System.out.println(); }
loki assassin at Yahoo! Answers Visit the source
Other answers
System.out.println("Please enter the number of times that"); System.out.println("you would like to throw the dice: "); Scanner input = new Scanner (System.in); numberOfTimes = input.nextInt(); System.out.println("The chart showing " + numberOfTimes + " throws of the dice:"); As we want how many times 1 is thrown, 2 is thrown, better you take an array having six elements int count[]={0,0,0,0,0,0}; for(int i=0;i<numberOfTimes;i++) { dieResults = (int)(6.0*Math.random()) +1; //get random number count[dieResults]++; //increments the count value } You decide at most how many *'s are needed. Rather you have to normalize this data such that smallest value to be have 1 and highest value to be maximum number of *'s needed by you. I am not doing this normalization. You can do on your own. for(i int i=0;i<6;i++) { for(int j=0;j<count[i];j++) System.out.print("*"); System.out.println(); }
James Bond
Related Q & A:
- Why cant i view my contacts display image? please help if you know ,thanks?Best solution by Yahoo! Answers
- The pores on my face are wideninf by the minute. Please help me so that I can have them the normal size?Best solution by Yahoo! Answers
- I cannot get the toolbar with my favorites to appear...please help.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- Help with TV show, please help?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.