veronikaaa86

02. Family Trip

Nov 13th, 2021 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 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 nightPrice = Double.parseDouble(scanner.nextLine());
  12. int percentExpenses = Integer.parseInt(scanner.nextLine());
  13.  
  14. if (countNights > 7) {
  15. nightPrice = nightPrice * 0.95;
  16. }
  17.  
  18. double allNightsPrice = countNights * nightPrice;
  19. double additionalExpenses = budget * (percentExpenses / 100.0);
  20.  
  21. double totalExpenses = allNightsPrice + additionalExpenses;
  22.  
  23. double diff = Math.abs(totalExpenses - budget);
  24. if (budget >= totalExpenses) {
  25. System.out.printf("Ivanovi will be left with %.2f leva after vacation.", diff);
  26. } else {
  27. System.out.printf("%.2f leva needed.", diff);
  28. }
  29. }
  30. }
  31.  
  32.  
Add Comment
Please, Sign In to add comment