Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Logistics {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int packagesCount = Integer.parseInt(scanner.nextLine());
- double allWeight = 0;
- int busCount = 0;
- int truckCount = 0;
- int trainCount = 0;
- double price = 0;
- for (int i = 1; i <= packagesCount ; i++) {
- int weight = Integer.parseInt(scanner.nextLine());
- if (weight <= 3) {
- busCount += weight;
- price += weight * 200;
- allWeight += weight;
- }else if (weight <= 11) {
- truckCount += weight;
- price += weight * 175;
- allWeight += weight;
- }else {
- trainCount+= weight;
- price += weight * 120;
- allWeight += weight;
- }
- }
- double averagePrice = price / allWeight;
- double busPercent = busCount / allWeight * 100;
- double truckPercent = truckCount / allWeight * 100;
- double trainPercent = trainCount / allWeight * 100;
- System.out.printf("%.2f%n",averagePrice);
- System.out.printf("%.2f%%%n",busPercent);
- System.out.printf("%.2f%%%n",truckPercent);
- System.out.printf("%.2f%%",trainPercent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement