Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
1.7 kB
2
Indexable
Never
package LastYearExams;
 
import java.util.Scanner;
 
public class Exam {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
 
        int n = Integer.parseInt(scan.nextLine()); //broq na studenti
 
        double grade = 0;
 
        double fail = 0;
        int failCount = 0;
 
        double sreden = 0;
        int sredenCount = 0;
 
        double dobur = 0;
        int doburCount = 0;
 
        double top = 0;
        int topCount = 0;
 
        for (int i = 0; i < n; i++) {
            grade = Double.parseDouble(scan.nextLine());
 
            if (grade >= 2 && grade <= 2.99) {
                fail += grade;
                failCount++;
 
            } else if (grade >= 3 && grade <= 3.99) {
                sreden += grade;
                sredenCount++;
 
            } else if (grade >= 4 && grade <= 4.99) {
                dobur += grade;
                doburCount++;
 
            } else {
                top += grade;
                topCount++;
            }
        }
        double average = (fail + sreden + dobur + top) / n;
 
        double percentFail = failCount * 1.0 / n * 100;
        double percentSreden = sredenCount * 1.0 / n * 100;
        double percentDobur = doburCount * 1.0 / n * 100;
        double percentTop = topCount * 1.0 / n * 100;
 
        System.out.printf("Top students: %.2f%%%n", percentTop);
        System.out.printf("Between 4.00 and 4.99: %.2f%%%n", percentDobur);
        System.out.printf("Between 3.00 and 3.99: %.2f%%%n", percentSreden);
        System.out.printf("Fail: %.2f%%%n", percentFail);
        System.out.printf("Average: %.2f", average);
 
    }
}