Advertisement
myrdok123

P02FamilyTrip

Apr 20th, 2024
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package ExamPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P02FamilyTrip {
  6.  
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         double budget = Double.parseDouble(scanner.nextLine());
  12.         int countNights = Integer.parseInt(scanner.nextLine());
  13.         double priceForOneNight = Double.parseDouble(scanner.nextLine());
  14.         int percent = Integer.parseInt(scanner.nextLine());
  15.  
  16.         if (countNights > 7) {
  17.             priceForOneNight = priceForOneNight * 0.95;
  18.  
  19.  
  20.             double priceForAllNights = countNights * priceForOneNight;
  21.             double priceExpenses = budget * percent / 100.0;
  22.             double totalPrice = priceForAllNights + priceExpenses;
  23.  
  24.             double diff = Math.abs(totalPrice - budget);
  25.  
  26.             if (budget >= totalPrice) {
  27.                 System.out.printf("Ivanovi will be left with %.2f leva after vacation.", diff);
  28.             } else {
  29.                 System.out.printf("%.2f leva needed.", diff);
  30.             }
  31.  
  32.         }
  33.  
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement