Helena12

Graduation2

Nov 4th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Graduation2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String studentName = scanner.nextLine();
  8.         int schoolClass = 1;
  9.         double yearlyGradesSum = 0;
  10.         int notPassed = 0;
  11.  
  12.         while (schoolClass <= 12 && notPassed < 2) {
  13.             double grade = Double.parseDouble(scanner.nextLine());
  14.             if (grade >= 4.00) {
  15.                 yearlyGradesSum+=grade;
  16.                 schoolClass++;
  17.             } else {
  18.                 notPassed += 1;
  19.             }
  20.         }
  21.  
  22.         if (notPassed < 2) {
  23.             double average = yearlyGradesSum / 12;
  24.             System.out.printf("%s graduated. Average grade: %.2f", studentName, average);
  25.         } else {
  26.             System.out.printf("%s has been excluded at %d grade", studentName, schoolClass);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment