Advertisement
CR7CR7

bravo

Feb 23rd, 2023
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TouristShopWithoutBoolean {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         String productName = scanner.nextLine();
  9.  
  10.         int productsPurchased = 0;
  11.         double totalCost = 0;
  12.         int counter = 0;
  13.  
  14.         while (!productName.equals("Stop")) {
  15.             double productPrice = Double.parseDouble(scanner.nextLine());
  16.             counter++;
  17.             if (counter % 3 == 0) {
  18.                 productPrice *= 0.5;
  19.             }
  20.             totalCost += productPrice;
  21.  
  22.             if (totalCost > budget) {
  23.                 System.out.println("You don't have enough money!");
  24.                 System.out.printf("You need %.2f leva!", totalCost - budget);
  25.                 break;
  26.             } else {
  27.                 productsPurchased++;
  28.             }
  29.  
  30.             productName = scanner.nextLine();
  31.         }
  32.         if (productName.equals("Stop")) {
  33.             System.out.printf("You bought %d products for %.2f leva.", productsPurchased, totalCost);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement