Advertisement
veronikaaa86

04. Tourist Shop

Oct 22nd, 2022
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05TouristShop {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double budget = Double.parseDouble(scanner.nextLine());
  10.  
  11.         int countProduct = 0;
  12.         double copyBudget = budget;
  13.         String inputLine = scanner.nextLine();
  14.         boolean isNotEnough = false;
  15.         while (!inputLine.equals("Stop")) {
  16.             String product = inputLine;
  17.             double priceProduct = Double.parseDouble(scanner.nextLine());
  18.             countProduct++;
  19.  
  20.             if (countProduct % 3 == 0) {
  21.                 priceProduct = priceProduct / 2;
  22.             }
  23.  
  24.             copyBudget = copyBudget - priceProduct;
  25.  
  26.             if (copyBudget < 0) {
  27.                 isNotEnough = true;
  28.                 break;
  29.             }
  30.  
  31.             inputLine = scanner.nextLine();
  32.         }
  33.  
  34.         if (isNotEnough) {
  35.             System.out.println("You don't have enough money!");
  36.             System.out.printf("You need %.2f leva!%n", Math.abs(copyBudget));
  37.         } else {
  38.             System.out.printf("You bought %d products for %.2f leva.%n", countProduct, budget - copyBudget);
  39.         }
  40.  
  41.  
  42.     }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement