Advertisement
kalin729

Graduation2

Apr 7th, 2021
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Graduation2 {
  6.  
  7.     public static Scanner s = new Scanner(System.in);
  8.     private static boolean excl = false;
  9.  
  10.     public static double testGrade(double getGrade, boolean flag) {
  11.         if (getGrade >= 4) {
  12.             return getGrade;
  13.         } else {
  14.             if (!flag) {
  15.                 getGrade = Double.parseDouble(s.nextLine());
  16.                 testGrade(getGrade, true);
  17.             } else {
  18.                 excl = true;
  19.             }
  20.             return 0;
  21.         }
  22.  
  23.     }
  24.  
  25.     public static void main(String[] args) {
  26.  
  27.         String name = s.nextLine();
  28.         double grade = 0;
  29.         double sum = 0;
  30.         int gradeExcl = 0;
  31.  
  32.         while (!excl && gradeExcl<12) {
  33.             gradeExcl++;
  34.             grade = Double.parseDouble(s.nextLine());
  35.             sum += testGrade(grade, false);
  36.         }
  37.  
  38.         if (excl){
  39.             System.out.println(name + " has been excluded at " + gradeExcl + " grade");
  40.         }else{
  41.             System.out.printf("%s graduated. Average grade: %.02f", name, sum/12);
  42.         }
  43.  
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement