myrdok123

P04TrainTheTrainers

Feb 12th, 2023
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. package NestedLoops.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04TrainTheTrainers {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int countPeople = Integer.parseInt(scanner.nextLine());
  11.         String input = scanner.nextLine();
  12.  
  13.         double totalGradesSum = 0;
  14.         int countPresentations = 0;
  15.  
  16.  
  17.         while (!input.equals("Finish")){
  18.  
  19.            
  20.             double sumGrades = 0;
  21.  
  22.             for (int i = 1; i <= countPeople ; i++) {
  23.                 double currentGrade = Double.parseDouble(scanner.nextLine());
  24.                 sumGrades += currentGrade;
  25.  
  26.             }
  27.  
  28.             double averageGradePerPresentation = sumGrades / countPeople;
  29.             totalGradesSum += averageGradePerPresentation;
  30.             countPresentations++;
  31.  
  32.             System.out.printf("%s - %.2f.%n", input, averageGradePerPresentation);
  33.  
  34.  
  35.             input = scanner.nextLine();
  36.         }
  37.  
  38.  
  39.         System.out.printf("Student's final assessment is %.2f.", totalGradesSum/countPresentations );
  40.  
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment