Advertisement
Stelios_Gakis

Seminar_1/Task_4

Sep 16th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. package Seminar_1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Task_4 {
  6.     public static void main(String[] args){
  7.  
  8.         Scanner input = new Scanner(System.in);
  9.         double stud;
  10.         double  u=0, low=0, mid = 0, high = 0 ;
  11.         double score;
  12.  
  13.         System.out.println("Please insert the number of students");
  14.         stud = input.nextInt();
  15.  
  16.         for (int i = 1; i <= stud; i++ ) {
  17.             System.out.println("Please insert grade for student number (" + i + ") (Scores go from 0p to 40p)");
  18.             score = input.nextDouble();
  19.  
  20.             if (score >= 0 && score < 20) {
  21.                 u++;
  22.             } else if (score >= 20 && score < 30) {
  23.                 low++;
  24.             } else if (score >= 30 && score < 36) {
  25.                 mid++;
  26.             } else if (score >= 36 && score <= 40) {
  27.                 high++;
  28.             } else {
  29.                 System.out.println("Error, wrong score inserted!");
  30.                 i--;
  31.             }
  32.         }
  33.         double a = 100*u/stud, b = 100*low/stud, c = 100*mid/stud, d = 100*high/stud;
  34.         char p = '%';
  35.         System.out.printf("%nNumber of 'U (Fail)' grades: %.0f (%.2f%c)", u, a, p);
  36.         System.out.printf("%nNumber of '3' grades: %.0f (%.2f%c)", low, b, p);
  37.         System.out.printf("%nNumber of '4' grades: %.0f (%.2f%c)", mid, c, p);
  38.         System.out.printf("%nNumber of '5' grades: %.0f (%.2f%c)", high, d, p);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement