Advertisement
IrinaIgnatova

Spring Vacation Trip

Jun 28th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         int days = Integer.parseInt(scanner.nextLine());
  15.         double budget = Double.parseDouble(scanner.nextLine());
  16.         int people = Integer.parseInt(scanner.nextLine());
  17.         double fuelPerkm = Double.parseDouble(scanner.nextLine());
  18.         double foodPerDayPerPerso = Double.parseDouble(scanner.nextLine());
  19.         double roomPerDayPerPerson = Double.parseDouble(scanner.nextLine());
  20.  
  21.         double foodExpences = days * people * foodPerDayPerPerso;
  22.         double hotelExpences = days * people * roomPerDayPerPerson;
  23.         double currentExpences = foodExpences + hotelExpences;
  24.         double consumedFuel = 0;
  25.         double additionalExpences = 0;
  26.         double receivedMoney = 0;
  27.         // System.out.println(foodExpences);
  28.         //System.out.println(hotelExpences);
  29.  
  30.         if (people > 10) {
  31.             double discount = 0.25 * hotelExpences;
  32.             hotelExpences -= discount;
  33.             currentExpences = foodExpences + hotelExpences;
  34.         }
  35.         for (int i = 1; i <= days; i++) {
  36.             double distanceKm = Double.parseDouble(scanner.nextLine());
  37.  
  38.             consumedFuel = distanceKm * fuelPerkm;
  39.             currentExpences += consumedFuel;
  40.  
  41.  
  42.             if (i % 3 == 0 || i % 5 == 0) {
  43. //                additionalExpences = 0.4 * currentExpences;
  44. //                currentExpences += additionalExpences;
  45.                 currentExpences *= 1.4;
  46.  
  47.             }
  48.             if (i % 7 == 0) {
  49. //                receivedMoney = currentExpences / people;
  50. //                currentExpences -= receivedMoney;
  51.                 currentExpences -= currentExpences / people;
  52.  
  53.             }
  54.             if (currentExpences > budget) {
  55.                 double moneyNeeded = currentExpences - budget;
  56.                 System.out.printf("Not enough money to continue the trip. You need %.2f$ more.", moneyNeeded);
  57.                 return;
  58.             }
  59.  
  60.  
  61.         }
  62.  
  63.         double moneyLeft = budget - currentExpences;
  64.         System.out.printf("You have reached the destination. You have %.2f$ budget left.", moneyLeft);
  65.  
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement