// Fig. 4.10: Analysis.java

// Java extension packages
import javax.swing.JOptionPane; 

public class Analysis
{
	
		// Main method begins execution of Java application
		public static void main ( String args[] )
		{
			
			int gradeCounter,  	// number of grades entered
				pass,			// the pass grade counter
				tester,			// temprary test value
				fail;			// the fail grade counter
			String grade,		// grade typed by user
					output;		// output strong
				
			
			// initialization phase
			pass = 0;		// clear the pass
			fail = 0;		// clear the fail
			gradeCounter = 1;
			
			// Processing phase using While loop
			while ( gradeCounter <= 10 ) 
			{
			
				// prompt for input and read grade from user
				grade = JOptionPane.showInputDialog (
					 "Enter 1 for pass 2 for fail: " );
				
				// convert grade from a String into an integer
				tester = Integer.parseInt( grade );
				
				// ensure the input is 1 or 2
				if ( tester != 1 && tester != 2 )
					JOptionPane.showMessageDialog( null,
					"Not a valid number", "Error", 
					JOptionPane.ERROR_MESSAGE );
				else
					gradeCounter = gradeCounter + 1;
					// test for 1 = pass
					if ( tester == 1 )
						pass = pass + 1; // add 1 to pass
					else
						if ( tester == 2 )
							fail += 1; // add 1 to fail, short hand +=
			}
			// Termination Phase, test if pass is greter than 8
			output = "Passed: " +pass +
				"\nFailed: " +fail;
				
			if (pass > 8)
				output = output + "\nRaise Tuition";
				
			JOptionPane.showMessageDialog( null, output,
			"Analysis of Exaination Result",
	 		JOptionPane.INFORMATION_MESSAGE );
				
			System.exit( 0 ); // teminate the program
			
		} // end method main

} // end class Analysis