TZinovieva

Family Trip Семейна почивка 100/100

Apr 16th, 2022 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package ExamPreparation;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FamilyTrip {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double budget = Double.parseDouble(scanner.nextLine());
  10.         int nights = Integer.parseInt(scanner.nextLine());
  11.         double nightPrice = Double.parseDouble(scanner.nextLine());
  12.         double extraCosts = Double.parseDouble(scanner.nextLine());
  13.  
  14.         extraCosts = extraCosts * budget / 100;
  15.  
  16.         if (nights > 7) {
  17.             nightPrice = nightPrice - nightPrice * 5 / 100;
  18.         }
  19.         double tripSum = (nights * nightPrice) + extraCosts;
  20.  
  21.         if (tripSum <= budget) {
  22.             System.out.printf("Ivanovi will be left with %.2f leva after vacation.", Math.abs(budget - tripSum));
  23.         } else {
  24.             System.out.printf("%.2f leva needed.", Math.abs(tripSum - budget));
  25.         }
  26.     }
  27. }
  28.  
Add Comment
Please, Sign In to add comment