Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Ex12 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int y; // grade entered by the user
- int c = 0; // count valid grades
- int sum = 0;
- double avg;
- double max = 0;
- int classesNo;
- String className;
- int pupilsInClass;
- int excelent = 0;
- int excelentInClass = 0;
- int maxExcelentInClass = 0;
- String maxClassName = "";
- System.out.print("enter the number of the classes: ");
- classesNo = in.nextInt();
- for (int j = 0; j < classesNo; j++) {
- // new class
- max = 0;
- excelentInClass = 0;
- System.out.print("Enter class name: ");
- className = in.next();
- System.out.print("Enter number of pupils in class " + className + ": ");
- pupilsInClass = in.nextInt();
- for (int i = 0; i < pupilsInClass; i++) {
- // new student
- System.out.println("* * * New Pupil Data * * *");
- c = 0;
- sum = 0;
- // get first grade
- System.out.print("Enter your grade (0 to 100): ");
- y = in.nextInt();
- while (y >= 0 && y <= 100) {
- // valid grade
- c++; // add 1 to the counter
- sum = sum + y; // add grade to sum
- // get next grade
- System.out.print("Enter your grade (0 to 100): ");
- y = in.nextInt();
- }
- System.out.println("You have " + c + " grades");
- System.out.println("The sum of grades is " + sum);
- avg = (double) sum / c;
- System.out.println("The average is " + avg);
- if (avg > max) {
- max = avg;
- }
- if (avg > 92) {
- excelentInClass++;
- excelent++;
- }
- }
- System.out.println("excelent in class are: " + excelentInClass);
- System.out.println("max average is " + max);
- if (excelentInClass > maxExcelentInClass) {
- maxExcelentInClass = excelentInClass;
- maxClassName = className;
- } else if (excelentInClass == maxExcelentInClass) {
- maxExcelentInClass = excelentInClass;
- maxClassName = maxClassName + ", " + className;
- }
- }
- System.out.println("the number of excelent pupils is " + excelent);
- System.out.println("max number of excelent pupils is class is " + maxExcelentInClass);
- System.out.println("max excelent pupils are in class " + maxClassName);
- in.close();
- }
- }
Add Comment
Please, Sign In to add comment