Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Logistics_03 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countGoods = Integer.parseInt(scanner.nextLine());
- double averagePriceGoods = 0;
- double busPrice = 0;
- double truckPrice = 0;
- double trainPrice = 0;
- int allGoods = 0;
- double busPercent = 0;
- int countBus = 0;
- double truckPercent = 0;
- int countTruck = 0;
- double trainPercent = 0;
- int countTrain = 0;
- for (int i = 1; i <=countGoods ; i++) {
- int goods = Integer.parseInt(scanner.nextLine());
- if (goods <= 4){
- busPrice =(busPrice) + 200 * goods;
- countBus += goods;
- }else if (goods <= 11){
- truckPrice =(truckPrice) + 175 * goods;
- countTruck += goods;
- }else {
- trainPrice =(trainPrice) + 120 * goods;
- countTrain += goods;
- }
- allGoods += goods;
- }
- averagePriceGoods = (busPrice + trainPrice + truckPrice) / allGoods;
- busPercent = (countBus*1.0 / allGoods) * 100;
- truckPercent = (countTruck * 1.0 / allGoods) * 100;
- trainPercent = (countTrain * 1.0 / allGoods) * 100;
- System.out.printf("%.2f%n", averagePriceGoods);
- System.out.printf("%.2f%%%n", busPercent);
- System.out.printf("%.2f%%%n", truckPercent);
- System.out.printf("%.2f%%", trainPercent);
- }
- }
Add Comment
Please, Sign In to add comment