Advertisement
damesova

Spring Vacation Trip [Mimi]

Apr 15th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class _01_Task {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int days = Integer.parseInt(scanner.nextLine());
  8.         double budget = Double.parseDouble(scanner.nextLine());
  9.         int people = Integer.parseInt(scanner.nextLine());
  10.         double fuelKM = Double.parseDouble(scanner.nextLine());
  11.         double foodPersonDay = Double.parseDouble(scanner.nextLine());
  12.         double priceNightPerson = Double.parseDouble(scanner.nextLine());
  13.  
  14.         double hotelExp;
  15.  
  16.         if (people > 10) {
  17.             hotelExp = (days *people * priceNightPerson) - ((days * people * priceNightPerson) * 0.25);
  18.         } else {
  19.             hotelExp = days * people * priceNightPerson;
  20.         }
  21.         double foodExp = days * people * foodPersonDay;
  22.         double currentExp = foodExp + hotelExp;
  23.  
  24.         for (int i = 1; i <= days; i++) {
  25.             if (currentExp >= budget) {
  26.                 break;
  27.             }
  28.  
  29.             double km = Double.parseDouble(scanner.nextLine());
  30.             double travelExp = km * fuelKM;
  31.  
  32.             currentExp += travelExp;
  33.  
  34.             if (i % 3 == 0 || i % 5 == 0) {
  35.                 currentExp += (currentExp * 0.4);
  36.             }
  37.  
  38.             if (i % 7 == 0) {
  39.                 double addMoney = currentExp / people;
  40.                 currentExp -= addMoney;
  41.             }
  42.         }
  43.  
  44.  
  45.         if (budget >= currentExp) {
  46.             System.out.printf("You have reached the destination. You have %.2f$ budget left.", budget - currentExp);
  47.         }
  48.         else {
  49.             System.out.printf("Not enough money to continue the trip. You need %.2f$ more.", currentExp - budget);
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement