Advertisement
veronikaaa86

02. Family Trip

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