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``````
2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by countrygirl1970

percentage is an array and you do:
percentage = frequency * 60000;

Also I think you have a problem with your brackets (})

``````public class Assignment5 extends JApplet
{

....
....

// Multiply the frequency to 60000 to get the percentage
line 38	percentage = frequency * 60000;

public void init()
{``````

I see what you were talking about. I went in and changed the names of the arrays and then added two lines to reenforce percentage and frequency. I am still getting the same error code for that line. I have all my brackets in place. Where do you see the problem at.

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 freq[] = new int [ 16 ];             // Array of frequency counters
int totalFrequency = 0;                  // Total of frequencies in the array
int perc[] = 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
int percentage = 0;
int frequency = 0;
line 40	percentage = frequency * 60000;

public void init()
{
// Summarize results of 60,000 rolls of the dice
for ( int totalRoll = 1; totalRoll <= 60000; totalRoll++ )
++freq[ 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``````

First of all this makes no sense:

``````int percentage = 0;
int frequency = 0;
percentage = frequency * 60000;``````

And second the above code is written were you declare variables, so you cannot put commands like this there: percentage = frequency * 60000;
This thing needs to go inside a method

Your brackets are OK, that was my mistake

Thank you, I see what you are saying and I am fixing a little at a time. I have taken that statement out. Thanks again.

countrygirl1970

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.