// NestedForLoops2.java
// Nested for loops summing an array
import java.awt.*;
import javax.swing.JApplet;

public class NestedForLoops2 extends JApplet {

	int sales[ ][ ] = { { 10, 5, 3, 2 }, { 20, 4, 8, 4 }, { 6, 10, 7, 10 } };
	int total[ ];  // declares the total array
	int yPos;

	public void init( ) {
		yPos = 25;
		total = new int[ 3 ];  // allocates the total array
	}

	public void paint( Graphics g ) {
		for ( int row = 0; row <= 2; row++ ) {
			for ( int col = 0; col <= 3; col++ ) {
				total[ row ] += sales[ row ][ col ];
			}
		}
		
		for ( int row = 0; row <= 2; row++ ) {
			g.drawString( "The total sales for salesperson " + ( row + 1 ) + " is " + total[ row ], 25, yPos );
			yPos += 20;
		}
	}
}