// NestedWhileLoops2.java
// Application demoing nested while loops summing an array
import javax.swing.*;

public class NestedWhileLoops2 {
	public static void main( String args[ ] ) {

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

  		// allocates the total array
		total = new int[ 3 ];

		int row = 0;
		int col;
		while ( row < 3 ) {
			col = 0;
			while ( col < 4 ) {
				total[ row ] += sales[ row ][ col ];
				col++;  // increment col inside the col loop
			}
			row++; // increment row outside the col loop but inside row loop
		}
		
		JTextArea outputArea = new JTextArea( 3, 40 );
		JScrollPane scroller = new JScrollPane( outputArea );

		row = 0;
		while ( row < 3 ) {
			outputArea.append( "The total sales for salesperson " + ( row + 1 ) + " is " + total[ row ] + "\n" + "\n" );
			row++;
		}

		JOptionPane.showMessageDialog( null, scroller, "Sales Array", JOptionPane.INFORMATION_MESSAGE );

		// terminate the program
		System.exit( 0 );
	}
}