Advertisement
Spocoman

Credit System

Sep 4th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine()),
  7.                 number;
  8.         double totalGrades = 0, totalCredits = 0;
  9.  
  10.         for (int i = 0; i < n; i++) {
  11.             number = Integer.parseInt(scanner.nextLine());
  12.             int grade = number % 10;
  13.             double credit = (int) number / 10;
  14.  
  15.             totalGrades += grade;
  16.  
  17.             if (grade == 2) {
  18.                 credit = 0;
  19.             } else if (grade == 3) {
  20.                 credit *= 0.50;
  21.             } else if (grade == 4) {
  22.                 credit *= 0.70;
  23.             } else if (grade == 5) {
  24.                 credit *= 0.85;
  25.             }
  26.  
  27.             totalCredits += credit;
  28.         }
  29.  
  30.         System.out.printf("%.2f\n%.2f\n", totalCredits, totalGrades / n);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement