Advertisement
Kathy2905

Spring

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