desislava_topuzakova

02. Add Bags

Mar 20th, 2021
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //обща цена за багажите = брой на багажите(вход) * цена за 1 багаж(тегло + брой дни)
  7.         double priceOver20kg = Double.parseDouble(scanner.nextLine());
  8.         double kg = Double.parseDouble(scanner.nextLine());
  9.         int daysToTrip = Integer.parseInt(scanner.nextLine());
  10.         int count = Integer.parseInt(scanner.nextLine());
  11.  
  12.         double pricePer = 0;
  13.  
  14.         //спрямо теглото
  15.         if(kg < 10) {
  16.             pricePer = 0.20 * priceOver20kg;
  17.         } else if (kg >= 10 && kg <= 20) {
  18.             pricePer = 0.50 * priceOver20kg;
  19.         } else if (kg > 20){
  20.             pricePer = priceOver20kg;
  21.         }
  22.  
  23.         //оскъпяване -> зависи от дните до почивката
  24.         if(daysToTrip > 30) {
  25.             pricePer = pricePer + 0.10 * pricePer; //1.1 * pricePer
  26.         } else if (daysToTrip >= 7 && daysToTrip <= 30) {
  27.             pricePer = pricePer + 0.15 * pricePer; // 1.15 * pricePer
  28.         } else if (daysToTrip < 7) {
  29.             pricePer = pricePer + 0.40 * pricePer; //1.4 * pricePer
  30.         }
  31.  
  32.         double totalPrice = count * pricePer;
  33.         System.out.printf("The total price of bags is: %.2f lv.", totalPrice);
  34.  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment