Lyubohd

02. Summer Shopping

Feb 22nd, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem02 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.        
  7.         int budget = Integer.parseInt(scan.nextLine());
  8.         double beachTowelPrice = Double.parseDouble(scan.nextLine());
  9.         int discount = Integer.parseInt(scan.nextLine());
  10.  
  11.         double umbrellaPrice = beachTowelPrice * 2 / 3;
  12.         double flipFlopsPrice = umbrellaPrice * 0.75;
  13.         double beachBagPrice = (flipFlopsPrice + beachTowelPrice) / 3;
  14.  
  15.         double totalPrice = beachTowelPrice + umbrellaPrice + flipFlopsPrice + beachBagPrice;
  16.         double discountPercent = discount * 1.0 / 100;
  17.         double finalPrice = totalPrice - totalPrice * discountPercent; // totalPrice * (1 - discount);
  18.  
  19.         //double diff = Math.abs(finalPrice - budget);
  20.         if (finalPrice > budget) { // 100 100
  21.             double moneyNeed = finalPrice - budget;
  22.             System.out.printf("Annie's sum is %.2f lv. She needs %.2f lv. more.", finalPrice, moneyNeed);
  23.         } else {
  24.             double moneyLeft = budget - finalPrice;
  25.             System.out.printf("Annie's sum is %.2f lv. She has %.2f lv. left.", finalPrice, moneyLeft);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment