silviasj

Logistics

Apr 4th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Logistics_03 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int countGoods = Integer.parseInt(scanner.nextLine());
  7.         double averagePriceGoods = 0;
  8.         double busPrice = 0;
  9.         double truckPrice = 0;
  10.         double trainPrice = 0;
  11.         int allGoods = 0;
  12.         double busPercent = 0;
  13.         int countBus = 0;
  14.         double truckPercent = 0;
  15.         int countTruck = 0;
  16.         double trainPercent = 0;
  17.         int countTrain = 0;
  18.  
  19.         for (int i = 1; i <=countGoods ; i++) {
  20.             int goods = Integer.parseInt(scanner.nextLine());
  21.             if (goods <= 4){
  22.                 busPrice =(busPrice) + 200 * goods;
  23.                 countBus += goods;
  24.  
  25.             }else if (goods <= 11){
  26.                 truckPrice =(truckPrice) + 175 * goods;
  27.                 countTruck += goods;
  28.             }else {
  29.                 trainPrice =(trainPrice) + 120 * goods;
  30.                 countTrain += goods;
  31.             }
  32.  
  33.             allGoods += goods;
  34.         }
  35.         averagePriceGoods = (busPrice + trainPrice + truckPrice) / allGoods;
  36.         busPercent = (countBus*1.0 / allGoods) * 100;
  37.         truckPercent = (countTruck * 1.0 / allGoods) * 100;
  38.         trainPercent = (countTrain * 1.0 / allGoods) * 100;
  39.         System.out.printf("%.2f%n", averagePriceGoods);
  40.         System.out.printf("%.2f%%%n", busPercent);
  41.         System.out.printf("%.2f%%%n", truckPercent);
  42.         System.out.printf("%.2f%%", trainPercent);
  43.  
  44.  
  45.  
  46.     }
  47. }
Add Comment
Please, Sign In to add comment