Advertisement
psi_mmobile

Untitled

May 14th, 2022
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int loadCount = scanner.nextInt();
  5.         int loadTons = 0;
  6.        
  7.         int microbusPricePerTon = 200;
  8.         int truckPricePerTon = 175;
  9.         int trainPricePerTon = 120;
  10.        
  11.         int microbusLoad = 0;
  12.         int truckLoad = 0;
  13.         int trainLoad = 0;
  14.        
  15.         int totalLoad = 0;
  16.        
  17.         for (int i = 1; i <= loadCount; i++) {
  18.             loadTons = scanner.nextInt();
  19.             if (loadTons <= 3) {
  20.                 microbusLoad += loadTons;
  21.             }
  22.             if (loadTons >= 4 && loadTons <= 11) {
  23.                 truckLoad += loadTons;
  24.             }
  25.             if (loadTons >= 12) {
  26.                 trainLoad += loadTons;
  27.             }
  28.             totalLoad += loadTons;
  29.         }
  30.         double averagePricePerTon = ((double)((microbusLoad * microbusPricePerTon) + (truckLoad * truckPricePerTon) + (trainLoad * trainPricePerTon))) / totalLoad;
  31.         double microbusAverage = ((double)microbusLoad / totalLoad) * 100;
  32.         double truckAverage = ((double)truckLoad / totalLoad) * 100;
  33.         double trainAverage = ((double)trainLoad / totalLoad) * 100;
  34.        
  35.         System.out.printf("%.2f\n",averagePricePerTon);
  36.         System.out.printf("%.2f%%\n",microbusAverage);
  37.         System.out.printf("%.2f%%\n",truckAverage);
  38.         System.out.printf("%.2f%%\n",trainAverage);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement