Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int loadCount = scanner.nextInt();
- int loadTons = 0;
- int microbusPricePerTon = 200;
- int truckPricePerTon = 175;
- int trainPricePerTon = 120;
- int microbusLoad = 0;
- int truckLoad = 0;
- int trainLoad = 0;
- int totalLoad = 0;
- for (int i = 1; i <= loadCount; i++) {
- loadTons = scanner.nextInt();
- if (loadTons <= 3) {
- microbusLoad += loadTons;
- }
- if (loadTons >= 4 && loadTons <= 11) {
- truckLoad += loadTons;
- }
- if (loadTons >= 12) {
- trainLoad += loadTons;
- }
- totalLoad += loadTons;
- }
- double averagePricePerTon = ((microbusLoad * microbusPricePerTon) + (truckLoad * truckPricePerTon) + (trainLoad * trainPricePerTon)) / totalLoad;
- double microbusAverage = ((double)microbusLoad / totalLoad) * 100;
- double truckAverage = ((double)truckLoad / totalLoad) * 100;
- double trainAverage = ((double)trainLoad / totalLoad) * 100;
- System.out.printf("%.2f\n",averagePricePerTon);
- System.out.printf("%.2f%%\n",microbusAverage);
- System.out.printf("%.2f%%\n",truckAverage);
- System.out.printf("%.2f%%\n",trainAverage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement