Advertisement
Spocoman

Add Bags

Aug 31st, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double priceBagOver20kg = Double.parseDouble(scanner.nextLine()),
  7.                 bagWeight = Double.parseDouble(scanner.nextLine());
  8.         int dayBefore = Integer.parseInt(scanner.nextLine()),
  9.                 bagCount = Integer.parseInt(scanner.nextLine());
  10.  
  11.         if (bagWeight < 10) {
  12.             priceBagOver20kg /= 5;
  13.         } else if (bagWeight <= 20) {
  14.             priceBagOver20kg /= 2;
  15.         }
  16.  
  17.         if (dayBefore < 7) {
  18.             priceBagOver20kg *= 1.40;
  19.         } else if (dayBefore <= 30) {
  20.             priceBagOver20kg *= 1.15;
  21.         } else {
  22.             priceBagOver20kg *= 1.10;
  23.         }
  24.  
  25.         double totalPrice = priceBagOver20kg * bagCount;
  26.  
  27.         System.out.printf("The total price of bags is: %.2f lv.\n", totalPrice);
  28.     }
  29. }
  30.  
  31. ИЛИ:
  32.  
  33. import java.util.Scanner;
  34.  
  35. public class Main {
  36.     public static void main(String[] args) {
  37.         Scanner scanner = new Scanner(System.in);
  38.         double priceBagOver20kg = Double.parseDouble(scanner.nextLine()),
  39.                 bagWeight = Double.parseDouble(scanner.nextLine());
  40.         int dayBefore = Integer.parseInt(scanner.nextLine()),
  41.                 bagCount = Integer.parseInt(scanner.nextLine());
  42.  
  43.         double totalPrice =
  44.                 priceBagOver20kg / (bagWeight < 10 ? 5 : bagWeight <= 20 ? 2 : 1)
  45.                         * (dayBefore < 7 ? 1.40 : dayBefore <= 30 ? 1.15 : 1.10) * bagCount;
  46.  
  47.         System.out.printf("The total price of bags is: %.2f lv.\n", totalPrice);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement