Advertisement
mmayoub

Ex10, 19.06.2021

Jun 20th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ex10 {
  4.     public static void main(String[] args) {
  5.         Scanner in = new Scanner(System.in);
  6.         int y; // grade entered by the user
  7.         int c = 0; // count valid grades
  8.         int sum = 0;
  9.         double avg;
  10.         double max = 0;
  11.         int classesNo;
  12.  
  13.         String className;
  14.         int pupilsInClass;
  15.  
  16.         int excelent = 0;
  17.  
  18.         System.out.print("enter the number of the classes: ");
  19.         classesNo = in.nextInt();
  20.  
  21.         for (int j = 0; j < classesNo; j++) {
  22.             // new class
  23.             max = 0;
  24.  
  25.             System.out.print("Enter class name: ");
  26.             className = in.next();
  27.             System.out.print("Enter number of pupils in class " + className + ": ");
  28.             pupilsInClass = in.nextInt();
  29.  
  30.             for (int i = 0; i < pupilsInClass; i++) {
  31.                 // new student
  32.                 System.out.println("* * * New Pupil Data * * *");
  33.                 c = 0;
  34.                 sum = 0;
  35.  
  36.                 // get first grade
  37.                 System.out.print("Enter your grade (0 to 100): ");
  38.                 y = in.nextInt();
  39.  
  40.                 while (y >= 0 && y <= 100) {
  41.                     // valid grade
  42.                     c++; // add 1 to the counter
  43.                     sum = sum + y; // add grade to sum
  44.  
  45.                     // get next grade
  46.                     System.out.print("Enter your grade (0 to 100): ");
  47.                     y = in.nextInt();
  48.                 }
  49.  
  50.                 System.out.println("You have " + c + " grades");
  51.                 System.out.println("The sum of grades is " + sum);
  52.                 avg = (double) sum / c;
  53.                 System.out.println("The average is " + avg);
  54.  
  55.                 if (avg > max) {
  56.                     max = avg;
  57.                 }
  58.  
  59.                 if (avg > 92) {
  60.                     excelent++;
  61.                 }
  62.             }
  63.  
  64.             System.out.println("max average is " + max);
  65.         }
  66.  
  67.         System.out.println("the number of excelent pupils is " + excelent);
  68.         in.close();
  69.     }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement