Advertisement
Deiancom

Logistics

Feb 8th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Logistics {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int packagesCount = Integer.parseInt(scanner.nextLine());
  7.  
  8.         double allWeight = 0;
  9.         int busCount = 0;
  10.         int truckCount = 0;
  11.         int trainCount = 0;
  12.         double price = 0;
  13.         for (int i = 1; i <= packagesCount ; i++) {
  14.             int weight = Integer.parseInt(scanner.nextLine());
  15.             if (weight <= 3) {
  16.                 busCount += weight;
  17.                 price += weight * 200;
  18.                 allWeight += weight;
  19.             }else if (weight <= 11) {
  20.                 truckCount += weight;
  21.                 price += weight * 175;
  22.                 allWeight += weight;
  23.             }else {
  24.                 trainCount+= weight;
  25.                 price += weight * 120;
  26.                 allWeight += weight;
  27.             }
  28.         }
  29.         double averagePrice = price / allWeight;
  30.         double busPercent = busCount / allWeight * 100;
  31.         double truckPercent = truckCount / allWeight * 100;
  32.         double trainPercent = trainCount / allWeight * 100;
  33.         System.out.printf("%.2f%n",averagePrice);
  34.         System.out.printf("%.2f%%%n",busPercent);
  35.         System.out.printf("%.2f%%%n",truckPercent);
  36.         System.out.printf("%.2f%%",trainPercent);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement