The program creates a 6x5 table with each column a salesperson and each row a product. 5 products and 4 salespeople (count starts at 0) The last row and last column are the totals.
javac gives no errors but when I run the appletviewer I get applet not initialized plus this in the terminal
What am I doing wrong?
Code:
import java.awt.*;
import javax.swing.*;
//*************************************************************
public class Test extends JApplet {
JTextArea outputArea;
String output;
int array[][] = new int[5][4];
int person, product;
//*************************************************************
public void init() {
outputArea = new JTextArea();
Container c = getContentPane();
c.add( outputArea );
person = array.length;
product = array[0].length;
buildArray ();
productTotal ();
personTotal ();
buildOutput ();
outputArea.setFont(
new Font( "Courier", Font.PLAIN, 12 ) );
outputArea.setText( output );
}
//*************************************************************
public void buildArray () {
for ( int i = 0; i < person; i++ ) {
for ( int j = 0; j < product; j++ ) {
for ( int day = 0; day < 30; day++ )
array[j][i] += 1 + (int) ( Math.random() * 5 );
}
}
}
//*************************************************************
public void productTotal () {
for ( int i = 0; i < person; i++ ) {
array[5][i] = 0;
for ( int j = 0; j < product; j++ ) {
array[j][4] = 0;
}
}
for ( int i = 0; i < person; i++ ) {
for ( int j = 0; j < product; j++ ) {
array[j][4] += array[i][j];
}
}
}
//*************************************************************
public void personTotal () {
for ( int i = 0; i < product; i++ ) {
for ( int j = 0; j < person; j++ ) {
array[5][j] += array[i][j];
}
}
}
//*************************************************************
public void buildOutput() {
output += " ";
for ( int i = 0; i < person; i++ )
output += "Person" + i + " ";
for ( int j = 0; j < product; j++ ) {
output += "\nProduct" + j + " ";
for ( int i = 0; i < person; i++ )
output += array[j][i] + " ";
}
}
}
javac gives no errors but when I run the appletviewer I get applet not initialized plus this in the terminal
java.lang.ArrayIndexOutOfBoundsException
at Test.buildArray(Test.java:53)
at Test.init(Test.java:29)
at sun.applet.AppletPanel.run(AppletPanel.java:341)
at java.lang.Thread.run(Thread.java:536)
What am I doing wrong?