I am trying to get this code working and it is giving me some error codes. The program is about rolling 3 dice together.
1) is to figure the frequency of the sum of all the dice rolled 60000 times
2) is to figure the precentage of the sum of all the dice rolled 60000 times
3) at the end show the total for frenquency and percentage
Here is the code:
// Displaying multiple strings
import javax.swing.*; // To use JOptionPane.showInputDialog box
import java.util.Random; // To use Random number generator
import java.awt.Graphics; // import class Graphics
public class Assignment5 extends JApplet
{
public class Dice
{
public static void main (String[] args)
{
Random randomNumbers = new Random(); // Random number generator
int frequency[] = new int [ 16 ]; // Array of frequency counters
int totalFrequency = 0; // Total of frequencies in the array
int percentage[] = new int [ 16 ]; // Array of percentage counters
int totalPercentage = 0; // Total of percentages in the array
// Summarize results of 60,000 rolls of the dice
for ( int totalRoll = 1; totalRoll <= 60000; totalRoll++ )
++frequency[ 1 + randomNumbers.nextInt (6) ];
// Rolling of three dice
int firstDie = (int) (6 * Math.random ()) + 1; // Roll one die
int secondDie = (int) (6 * Math.random ()) + 1; // Roll second die
int thirdDie = (int) (6 * Math.random ()) + 1; // Roll third die
int totalRoll = firstDie + secondDie + thirdDie; // Total of the three dice
// Multiply the frequency to 60000 to get the percentage
percentage = frequency * 60000;
// initialize applet by obtaining values from user
line 50 public void init()
{
// Add each frequency's value to get total
for ( int counter = 0; counter < array.length; counter++ )
totalFrequency += array[ counter ];
// Add each percentage's value to get total
for ( int counterPer = 0; counterPer < array.length; counterPer++ )
totalPercentage += array [ counterPer ];
} // End init
// draw results in a rectangle on applet's background
public void paint( Graphics g )
{
super.paint( g ); // call class version of method paint
// draw results as a String
g.drawString( "Sum" , "Frequency" , "%" );
// draw line as a String
line 72 g.drawString(---------------------------------);
// draw results as a String
75 g.drawString( "3" + frequency +, + percentage );
76 g.drawString( "4" + frequency +, + percentage );
77 g.drawString( "5" + frequency +, + percentage );
78 g.drawString( "6" + frequency +, + percentage );
79 g.drawString( "7" + frequency +, + percentage );
80 g.drawString( "8" + frequency +, + percentage );
81 g.drawString( "9" + frequency +, + percentage );
82 g.drawString( "10" + frequency +, + percentage );
83 g.drawString( "11" + frequency +, + percentage );
84 g.drawString( "12" + frequency +, + percentage );
85 g.drawString( "13" + frequency +, + percentage );
86 g.drawString( "14" + frequency +, + percentage );
87 g.drawString( "15" + frequency +, + percentage );
88 g.drawString( "16" + frequency +, + percentage );
89 g.drawString( "17" + frequency +, + percentage );
90 g.drawString( "18" + frequency +, + percentage );
// draw line as a String
93 g.drawString(----------------------------------);
// draw results as a String
96 g.drawString( "Total" + totalFrequency +, + totalPercentage );
} // end method paint
} // end main
} // end class dice
106 } // end class Assignment5
here are the error codes that I am getting:
illegal start of expression on lines:
50, 72, 75-90, 93, 96
class, interface, or enum expected:
106
Here is what the program will look like at the end:
sum frequency percentage
-------------------------------------------
3 254 0.42%
" " "
18 284 0.47%
-------------------------------------------
total 60000 100.00%
I just need some help to point me in the right direction.
Thank you,
countrygirl1970

New Topic/Question
Reply




MultiQuote






|