Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. // Fig. 3.10: Analysis.java
  2. // Analysis of examination results.
  3. import java.util.Scanner; // class uses class Scanner
  4.  
  5. public class Analysis
  6. {
  7.     public static void main( String[] args )
  8.     {
  9.       // Create Scanner to obtain input from command window
  10.       Scanner input = new Scanner( System.in );
  11.      
  12.       // initializing variables in declarations
  13.       int passes = 0; // number of passes
  14.       int failures = 0; // number of failures
  15.       int studentCounter = 1; // student counter
  16.       int result; // one exam result (obtains value from user)
  17.  
  18.       // process 10 students using counter-controlled loop
  19.       while ( studentCounter<= 10 )
  20.       {
  21.             // prompt user for input and obtain value from user
  22.         System.out.print( "Enter result (1 = pass, 2 = fail): " );
  23.         result = input.nextInt();
  24.  
  25.         // if...else nested in while
  26.         if ( result == 1 )          // if result 1,
  27.            passes = passes + 1;     // increment passes;
  28.         else                        // else result is not 1, so
  29.                failures = failures + 1; // increment failures
  30.  
  31.         // increment counter so loop eventually terminates
  32.         studentCounter = studentCounter + 1;
  33.       } // end while
  34.      
  35.          // termination phase; prepare and display results
  36.          System.out.printf( "Passed: %d\n", passes, failures );
  37.  
  38.      // determine whether more than 8 students passed
  39.     if ( passes > 8 )
  40.        System.out.println( "Bonus to instructor!" );
  41.     } // end main
  42. } // end class Analysis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement