Advertisement
CR7CR7

shopT

Feb 23rd, 2023
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TouristShop {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.  
  8.         double budget = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int productsCount = 0;
  11.         double moneyLeft = budget;
  12.         boolean noMoney = false;
  13.  
  14.         String input = scanner.nextLine();
  15.  
  16.         while (!input.equals("Stop")) {
  17.  
  18.             String product = input;
  19.             double price = Double.parseDouble(scanner.nextLine());
  20.             productsCount++;
  21.  
  22.             if (productsCount % 3 == 0) {
  23.                 price *= 0.50;
  24.             }
  25.             moneyLeft -= price;
  26.  
  27.             if (moneyLeft < 0) {
  28.                 noMoney = true;
  29.                 break;
  30.             }
  31.             input = scanner.nextLine();
  32.  
  33.         }
  34.         if (noMoney) {
  35.             System.out.printf("You don't have enough money!%nYou need %.2f leva!", Math.abs(moneyLeft));
  36.         } else {
  37.             System.out.printf("You bought %d products for %.2f leva.", productsCount, budget - moneyLeft);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement