Hello,
I am trying to get this code to work. I am getting an error code on line 38, that I don't understand why. Can anyone help me out. the error code that I am getting is identifier expected.
Thanks,
countrygirl1970
// 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
{
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
// 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
line 38 percentage = frequency * 60000;
public void init()
{
// Summarize results of 60,000 rolls of the dice
for ( int totalRoll = 1; totalRoll <= 60000; totalRoll++ )
++frequency[ 1 + randomNumbers.nextInt (6) ];
// 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 method 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" + "%" , 45, 35);
// draw line as a String
g.drawLine(10, 55, 100, 55);
// draw results as a String
g.drawString( "3" + frequency + percentage, 45, 75);
g.drawString( "4" + frequency + percentage, 45, 85);
g.drawString( "5" + frequency + percentage, 45, 95);
g.drawString( "6" + frequency + percentage, 45, 105);
g.drawString( "7" + frequency + percentage, 45, 115);
g.drawString( "8" + frequency + percentage, 45, 125);
g.drawString( "9" + frequency + percentage, 45, 135);
g.drawString( "10" + frequency + percentage, 45, 145);
g.drawString( "11" + frequency + percentage, 45, 155);
g.drawString( "12" + frequency + percentage, 45, 165);
g.drawString( "13" + frequency + percentage, 45, 175);
g.drawString( "14" + frequency + percentage, 45, 185);
g.drawString( "15" + frequency + percentage, 45, 195);
g.drawString( "16" + frequency + percentage, 45, 205);
g.drawString( "17" + frequency + percentage, 45, 215);
g.drawString( "18" + frequency + percentage, 45, 225);
// draw line as a String
g.drawLine(10, 245, 100, 245);
// draw results as a String
g.drawString( "Total" + totalFrequency + totalPercentage, 45, 265 );
} // end method paint
} // end Assignment5