Gpdev

SpiritVacationTrip

Mar 11th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class SpiritVacationTrip {
  6.     public static void main(String[] args) throws IOException {
  7.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  8.  
  9.  
  10.         int daysOfVacation = Integer.parseInt(reader.readLine());
  11.         double budget = Double.parseDouble(reader.readLine());
  12.         int group = Integer.parseInt(reader.readLine());
  13.         double fuelPerKilometer = Double.parseDouble(reader.readLine());
  14.         double foodPerPerson = Double.parseDouble(reader.readLine());
  15.         double priceRoomPerNight = Double.parseDouble(reader.readLine());
  16.  
  17.  
  18.  
  19.         double expForFood = foodPerPerson*group*daysOfVacation;
  20.  
  21.  
  22.         double costForHotel = priceRoomPerNight*group*daysOfVacation;
  23.  
  24.         if(group > 10) {
  25.             costForHotel = costForHotel - costForHotel * 0.25;
  26.         }
  27.  
  28.         if(budget - costForHotel < 0){
  29.             System.out.printf("Not enough money to continue the trip. You need %.2f$ more.",Math.abs(budget - costForHotel));
  30.             return;
  31.         }
  32.  
  33.         double fullExp = expForFood + costForHotel;
  34.         double consumedFuel = 0
  35.  
  36.         for (int i = 1; i <= daysOfVacation ; i++) {
  37.             double kilometer = Integer.parseInt(reader.readLine());
  38.  
  39.             consumedFuel = kilometer * fuelPerKilometer;
  40.  
  41.             fullExp += consumedFuel;
  42.  
  43.             if(i%3 == 0){
  44.                 fullExp += fullExp * 0.4;
  45.             }
  46.             if(i%5 == 0){
  47.                 fullExp += fullExp *  0.4;
  48.             }
  49.             if(i%7 == 0){
  50.                 fullExp = fullExp - fullExp/ group;
  51.             }
  52.  
  53.             if(budget - fullExp < 0){
  54.                 System.out.printf("Not enough money to continue the trip. You need %.2f$ more.",Math.abs(budget - fullExp));
  55.                 return;
  56.             }
  57.  
  58.         }
  59.           System.out.printf("You have reached the destination. You have %.2f$ budget left.", budget - fullExp);
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment