Advertisement
Vladkoheca

Zavurshvane.java

Apr 8th, 2024 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MyClass {
  4.     public static double calculateAverageGrade(double[] grades) {
  5.         double totalGrades = 0;
  6.         for (double grade : grades) {
  7.             totalGrades += grade;
  8.         }
  9.         return totalGrades / grades.length;
  10.     }
  11.  
  12.     public static void main(String[] args) {
  13.         Scanner scanner = new Scanner(System.in);
  14.  
  15.         System.out.print("Enter student's name: ");
  16.         String name = scanner.nextLine();
  17.  
  18.         double[] grades = new double[12];
  19.         boolean excluded = false;
  20.         int year = 1;
  21.  
  22.         while (year <= 12) {
  23.             System.out.print("Enter grade for year " + year + ": ");
  24.             double grade = scanner.nextDouble();
  25.             if (grade < 4) {
  26.                 System.out.println(name + " has been excluded at " + year + " grade");
  27.                 excluded = true;
  28.                 continue;
  29.             }
  30.             grades[year - 1] = grade;
  31.             year++;
  32.         }
  33.  
  34.         if (!excluded) {
  35.             double averageGrade = calculateAverageGrade(grades);
  36.             System.out.printf("%s graduated. Average grade: %.2f\n", name, averageGrade);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement