Advertisement
myrdok123

04. Train The Trainers

Jun 4th, 2023
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package L06_NestedLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04_TrainTheTrainers {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10.         int countPeople = Integer.parseInt(scanner.nextLine());
  11.         String input = scanner.nextLine();
  12.  
  13.         int countGrades = 0;
  14.         double sumAllGrades = 0;
  15.  
  16.         //while -> докато не получим Finish
  17.         while (!input.equals("Finish")){
  18.  
  19.             double sumGradesPerPresentation = 0;
  20.             // for -> прочитаме всяка една оценка
  21.             for (int i = 1; i <= countPeople ; i++) {
  22.                 double currentGrade = Double.parseDouble(scanner.nextLine());
  23.                 sumGradesPerPresentation += currentGrade;
  24.  
  25.                 //прибяваме  currentGrade към sumAllGrades
  26.                 sumAllGrades += currentGrade;
  27.  
  28.                 //увеличаваме броката на оценките
  29.                 countGrades++;
  30.  
  31.             }
  32.             //изчисляваме средната оценка за презентация
  33.             double averageGradePerPresentation = sumGradesPerPresentation / countPeople;
  34.  
  35.            
  36.  
  37.             System.out.printf("%s - %.2f.%n", input, averageGradePerPresentation);
  38.  
  39.  
  40.             input = scanner.nextLine();
  41.         }
  42.  
  43.  
  44.         //изчисляваме средната оценка за вдички студенти
  45.         double averageStudentsGrade = sumAllGrades / countGrades;
  46.  
  47.         System.out.printf("Student's final assessment is %.2f.", averageStudentsGrade);
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement