Advertisement
Valantina

FamilyTrip/Ex/Java

Jul 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P02_FamilyTrip {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scan.nextLine());
  8.         int nightCnt = Integer.parseInt(scan.nextLine());
  9.         double nightPrice = Double.parseDouble(scan.nextLine());
  10.         int percent = Integer.parseInt(scan.nextLine());
  11.  
  12.         if (nightCnt > 7) {
  13.             nightPrice = nightPrice * 0.95;
  14.         }
  15.  
  16.         double totalNightPrice = nightCnt * nightPrice;
  17.         double additionalCosts = budget * (percent / 100.0);
  18.  
  19.         double totalPrice = totalNightPrice + additionalCosts;
  20.         if (totalPrice > budget) {
  21.             double moneyNeed = totalPrice - budget;
  22.             System.out.println(String.format("%.2f leva needed.", moneyNeed));
  23.         } else {
  24.             double moneyLeft = budget - totalPrice;
  25.             System.out.println(String.format("Ivanovi will be left with %.2f leva after vacation.", moneyLeft));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement