desislava_topuzakova

08. Graduation -> While Loop Lab

Oct 23rd, 2021
586
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         String name = scanner.nextLine();
  11.         double level = 0;
  12.         double gradeTotal = 0.00;
  13.         boolean isFailed = false;
  14.         while (level != 12.0) {
  15.             double grade = Double.parseDouble(scanner.nextLine());
  16.             level++;
  17.  
  18.             if (grade < 4.0){
  19.                 isFailed = true;
  20.                 break;
  21.             } else {
  22.                 gradeTotal = gradeTotal + grade;
  23.             }
  24.         }
  25.         if (isFailed){
  26.             System.out.printf("%s has been excluded at %.0f grade", name, level);
  27.         }else {
  28.             System.out.printf("%s graduated. Average grade: %.2f", name, (gradeTotal / 12.00));
  29.  
  30.         }
  31.     }
  32. }
RAW Paste Data