Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SprigVac {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine());
- double budget = Double.parseDouble(scanner.nextLine());
- int people = Integer.parseInt(scanner.nextLine());
- double fuelPerKM = Double.parseDouble(scanner.nextLine());
- double foodExpenses = Double.parseDouble(scanner.nextLine());
- double priceHotelPerPeron = Double.parseDouble(scanner.nextLine());
- double finalExpence = 0.0;
- double totalFoodExpenses = foodExpenses * people * days;
- double totalHotelPrice = priceHotelPerPeron * people * days;
- if (people > 10){
- totalHotelPrice = totalHotelPrice - (0.25 * totalHotelPrice);
- }
- finalExpence = totalFoodExpenses + totalHotelPrice;
- for (int i = 1; i <= days ; i++) {
- double travelDistance = Double.parseDouble(scanner.nextLine());
- double consumedFuel = travelDistance * fuelPerKM;
- finalExpence+=consumedFuel;
- if (i % 3 == 0 || i % 5 == 0){
- finalExpence += 0.4 * finalExpence;
- }
- if (i % 7 == 0){
- finalExpence-= finalExpence/people;
- }
- if (finalExpence >= budget){
- break;
- }
- }
- if (budget >= finalExpence){
- System.out.printf("You have reached the destination. You have %.2f$ budget left.", budget-finalExpence);
- } else {
- System.out.printf("Not enough money to continue the trip. You need %.2f$ more.",finalExpence-budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement