Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class SpiritVacationTrip {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int daysOfVacation = Integer.parseInt(reader.readLine());
- double budget = Double.parseDouble(reader.readLine());
- int group = Integer.parseInt(reader.readLine());
- double fuelPerKilometer = Double.parseDouble(reader.readLine());
- double foodPerPerson = Double.parseDouble(reader.readLine());
- double priceRoomPerNight = Double.parseDouble(reader.readLine());
- double expForFood = foodPerPerson*group*daysOfVacation;
- double costForHotel = priceRoomPerNight*group*daysOfVacation;
- if(group > 10) {
- costForHotel = costForHotel - costForHotel * 0.25;
- }
- if(budget - costForHotel < 0){
- System.out.printf("Not enough money to continue the trip. You need %.2f$ more.",Math.abs(budget - costForHotel));
- return;
- }
- double fullExp = expForFood + costForHotel;
- double consumedFuel = 0
- for (int i = 1; i <= daysOfVacation ; i++) {
- double kilometer = Integer.parseInt(reader.readLine());
- consumedFuel = kilometer * fuelPerKilometer;
- fullExp += consumedFuel;
- if(i%3 == 0){
- fullExp += fullExp * 0.4;
- }
- if(i%5 == 0){
- fullExp += fullExp * 0.4;
- }
- if(i%7 == 0){
- fullExp = fullExp - fullExp/ group;
- }
- if(budget - fullExp < 0){
- System.out.printf("Not enough money to continue the trip. You need %.2f$ more.",Math.abs(budget - fullExp));
- return;
- }
- }
- System.out.printf("You have reached the destination. You have %.2f$ budget left.", budget - fullExp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment