Coolest Head
Posts: 5
Nickname: stkovrflow
Registered: Mar, 2004
|
|
Re: please help get compiler error
|
Posted: Mar 15, 2004 8:59 PM
|
|
> My assignmsent is to write a program that roll 3 dice and > repeat it 60000 times, sum the faces ,determines the > frequency for each sum and the percentages. Totals the > frequency and the prcentages. > Problems: Frequencies are not display in the applet. I > wrote another piece of code and compiler says > modifyArray(int) in Lab5 cannot be applied to > modifyArray(); > I was trying to modify the frequency array to obtain the > percentages. > Any help is greatly appreciated > Thanks > Nancy > > // Lab5.java
> // Applet that simulates rolling of 3 dice, sum the faces,
> display the frequency in percentages and total both the
> // frequency and the percentages
>
> import javax.swing.*;
> import java.awt.*;
> import java.awt.Container;
> public class Lab5 extends JApplet {
>
> JTextArea outputArea;
> int face,frequency[] = new int[ 19 ];
> String output= "";
> double percent = 0.00;
>
> public void init() {
> outputArea = new JTextArea();
> Container c = getContentPane();
> c.add (outputArea);
> outputArea.setFont(new Font("Courier", Font.ITALIC,
> C, 18));
>
> showArray();
>[u][b] modifyArray(); [/b][/u]
> }
> public int rollDice() {
> int die1, die2, die3;
>
> //roll dice 60000 times
> for ( int roll= 1; roll <= 60000; roll++) {
> die1 = 1 +(int) ( Math.random() * 6 );
> die2 = 1 +(int) ( Math.random() * 6 );
> die3 = 1 +(int) ( Math.random() * 6 );
>
> face = die1+die2+die3;
> }
> // use face value as subscript for frequency array
> ++frequency[ face ];
> return face;
> }
>
> public void showArray() {
> // append frequency to String output
> for (face=3; face < frequency.length; face++ ){
> output +="\n" + face + "\t" + frequency[face]+ "\t\t" +
> + percent;
>
> outputArea.setText("Sum\tFrequency\t%"+"\n" + output
> tput );//+ "\n\n" + "Total");
> }
> }
>
> public void modifyArray(int frequency) {
> percent = frequency/600;
>
>
> }
>
>
> }
>
Look at where you are calling modifyArray(). You are calling it without parameters and yet your function definition has a int parameter. Get the idea???
|
|