// Exercise 4.18 Solution: Analysis.java // Program performs analysis of examination results. // Java extension packages import javax.swing.JOptionPane; public class Analysis { // main method begins execution of Java application public static void main( String args[] ) { // initializing variables in declarations int passes = 0, failures = 0, student = 1, result; String input, output; // process 10 students; counter-controlled loop while ( student <= 10 ) { input = JOptionPane.showInputDialog( "Enter result (1=pass,2=fail): " ); result = Integer.parseInt( input ); if ( result == 1 ) { // if/else nested in while passes++; student++; } else if ( result == 2 ) { failures++; student++; } else JOptionPane.showMessageDialog( null, "Invalid Input", "Error", JOptionPane.ERROR_MESSAGE ); } output = "Passed: " + passes + "\nFailed: " + failures; if ( passes > 8 ) output += "\nRaise tuition "; JOptionPane.showMessageDialog( null, output, "Results", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } // end method main } // end class Analysis