Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: mindy broom
Added: Feb 5, 2021 7:37 PM
Views: 8
Tags: no tags
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package com.mindy.java.helloworldcars;
  8.  
  9. import java.util.Scanner;
  10.  
  11. /** @author Queen$ */
  12. public class example {}
  13. // Fig. 4.12: Analysis.java
  14. // Analysis of examination results using nested control statements.
  15. import java.util.Scanner; // class uses class Scanner
  16.  
  17. public class Analysis {
  18.    public static void main(String[] args) {
  19.       // create Scanner to obtain input from command window
  20.       Scanner input = new Scanner(System.in);
  21.  
  22.       // initializing variables in declarations
  23.       int passes = 0;
  24.       int failures = 0;
  25.       int studentCounter = 1;
  26.  
  27.       // process 10 students using counter-controlled loop
  28.       while (studentCounter <= 10) {
  29.          // prompt user for input and obtain value from user
  30.          System.out.print("Enter result (1 = pass, 2 = fail): ");
  31.          int result = input.nextInt();
  32.  
  33.          // if...else is nested in the while statement          
  34.          if (result == 1) {        
  35.             passes = passes + 1;  
  36.          }
  37.          else {                      
  38.             failures = failures + 1;
  39.          }
  40.  
  41.          // increment studentCounter so loop eventually terminates
  42.          studentCounter = studentCounter + 1;  
  43.       }
  44.  
  45.       // termination phase; prepare and display results
  46.       System.out.printf("Passed: %d%nFailed: %d%n", passes, failures);
  47.  
  48.       // determine whether more than 8 students passed
  49.       if (passes > 8) {
  50.          System.out.println("Bonus to instructor!");
  51.       }
  52.    }
  53. }
  54.  
  55. /**************************************************************************
  56.  * (C) Copyright 1992-2018 by Deitel & Associates, Inc. and               *
  57.  * Pearson Education, Inc. All Rights Reserved.                           *
  58.  *                                                                        *
  59.  * DISCLAIMER: The authors and publisher of this book have used their     *
  60.  * best efforts in preparing the book. These efforts include the          *
  61.  * development, research, and testing of the theories and programs        *
  62.  * to determine their effectiveness. The authors and publisher make       *
  63.  * no warranty of any kind, expressed or implied, with regard to these    *
  64.  * programs or to the documentation contained in these books. The authors *
  65.  * and publisher shall not be liable in any event for incidental or       *
  66.  * consequential damages in connection with, or arising out of, the       *
  67.  * furnishing, performance, or use of these programs.                     *
  68.  *************************************************************************/
  69.