desislava_topuzakova

02. Family Trip

Feb 19th, 2022
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FamilyTrip_02 {
  4.     public static void main(String[] args) {
  5.         //обща сума за почивка = сума за нощувки + допълнителни разходи
  6.         //сума за нощувки = бр. нощувки * цена за 1 нощувка
  7.         //допълнителни разходи = процент от бюджета
  8.         Scanner scanner = new Scanner(System.in);
  9.         double budget = Double.parseDouble(scanner.nextLine());
  10.         int count = Integer.parseInt(scanner.nextLine());
  11.         double pricePerNight = Double.parseDouble(scanner.nextLine());
  12.         int percent = Integer.parseInt(scanner.nextLine());
  13.  
  14.         if (count > 7) {
  15.             pricePerNight = pricePerNight - 0.05 * pricePerNight;
  16.             //0.95 * pricePerNight
  17.         }
  18.         double sumNights = count * pricePerNight;
  19.         double sumAddExpenses = (percent / 100.0) * budget;
  20.         double totalSum = sumNights + sumAddExpenses;
  21.  
  22.         //ако бюджетът е достатъчен
  23.         if (budget >= totalSum) {
  24.             double leftMoney = budget - totalSum;
  25.             System.out.printf("Ivanovi will be left with %.2f leva after vacation.", leftMoney);
  26.         } else {
  27.             //budget < totalSum
  28.             double needMoney = totalSum - budget;
  29.             System.out.printf("%.2f leva needed.", needMoney);
  30.         }
  31.  
  32.  
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment