Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- 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 foodPerDayPerPerso = Double.parseDouble(scanner.nextLine());
- double roomPerDayPerPerson = Double.parseDouble(scanner.nextLine());
- double foodExpences = days * people * foodPerDayPerPerso;
- double hotelExpences = days * people * roomPerDayPerPerson;
- double currentExpences = foodExpences + hotelExpences;
- double consumedFuel = 0;
- double additionalExpences = 0;
- double receivedMoney = 0;
- // System.out.println(foodExpences);
- //System.out.println(hotelExpences);
- if (people > 10) {
- double discount = 0.25 * hotelExpences;
- hotelExpences -= discount;
- currentExpences = foodExpences + hotelExpences;
- }
- for (int i = 1; i <= days; i++) {
- double distanceKm = Double.parseDouble(scanner.nextLine());
- consumedFuel = distanceKm * fuelPerkm;
- currentExpences += consumedFuel;
- if (i % 3 == 0 || i % 5 == 0) {
- // additionalExpences = 0.4 * currentExpences;
- // currentExpences += additionalExpences;
- currentExpences *= 1.4;
- }
- if (i % 7 == 0) {
- // receivedMoney = currentExpences / people;
- // currentExpences -= receivedMoney;
- currentExpences -= currentExpences / people;
- }
- if (currentExpences > budget) {
- double moneyNeeded = currentExpences - budget;
- System.out.printf("Not enough money to continue the trip. You need %.2f$ more.", moneyNeeded);
- return;
- }
- }
- double moneyLeft = budget - currentExpences;
- System.out.printf("You have reached the destination. You have %.2f$ budget left.", moneyLeft);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement