// Fig. 4.7: Average1.java
// Roy's time wasting Java applet

// Java extension packages
import javax.swing.JOptionPane; 

public class Average1
{
	
		// Main method begins execution of Java application
		public static void main ( String args[] )
		{
			
			int total,		 	// sum of grades input by user
				gradeCounter,  	// number of grades entered
				gradeValue, 	// grade value
				average;		// average of all grades
			String grade;		// grade typed by user
				
			
			// initialization phase
			total = 0;		// clear total
			gradeCounter = 1;
			
						
			// Processing phase using While loop
			while ( gradeCounter <= 10 ) 
			{	
				// prompt for input and read grade from user
				grade = JOptionPane.showInputDialog (
					 "Enter integer grade: " );
				
				// convert grade from a String into an integer
				gradeValue = Integer.parseInt( grade );
				
				// add grade value to the total
				total = total + gradeValue;
				
				// add 1 to gradeCounter
				gradeCounter = gradeCounter + 1;
			
			} // end while struture
			
			// Termination Phase
			average = total / 10; // performs integer division
			
			// Display the average of exam grades
			JOptionPane.showMessageDialog( null,
			"Class average is: " + average, "Class average", 
			JOptionPane.INFORMATION_MESSAGE );
			
			System.exit( 0 ); // teminate the program
			
		} // end method main

} // end class Average1