Advertisement
Spocoman

Computer Firm

Sep 3rd, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 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 modelCount = Integer.parseInt(scanner.nextLine()),
  7.                 model, rating, sales;
  8.         double totalSales = 0, totalRating = 0;
  9.  
  10.         for (int i = 0; i < modelCount; i++) {
  11.             model = Integer.parseInt(scanner.nextLine());
  12.             rating = model % 10;
  13.             sales = model / 10;
  14.             totalRating += rating;
  15.             totalSales += switch (rating) {
  16.                 case 2 -> 0;
  17.                 case 3 -> 0.5;
  18.                 case 4 -> 0.7;
  19.                 case 5 -> 0.85;
  20.                 default -> 1;
  21.             } * sales;
  22.         }
  23.  
  24.         System.out.printf("%.2f\n%.2f\n", totalSales, totalRating / modelCount);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement