Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
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 TouristShop {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         int counter = 0;
  9.         int productCount = 0;
  10.         boolean isDone = false;
  11.         double sum = 0;
  12.  
  13.  
  14.         String command = scanner.nextLine();
  15.         while (!"Stop".equals(command)) {
  16.             counter++;
  17.             String productName = command;
  18.             double priceProduct = Double.parseDouble(scanner.nextLine());
  19.             productCount++;
  20.  
  21.             if (counter == 3) {
  22.                 priceProduct /= 2;
  23.                 counter = 0;
  24.             }
  25.             sum += priceProduct;
  26.             budget -= priceProduct;
  27.             if (budget < priceProduct) {
  28.                 isDone = true;
  29.                 break;
  30.             }
  31.  
  32.             command = scanner.nextLine();
  33.         }
  34.         if (isDone) {
  35.             System.out.println("You don't have enough money!");
  36.             System.out.printf("You need %.2f leva!", Math.abs(budget));
  37.         } else {
  38.             System.out.printf("You bought %d products for %.2f leva.", productCount, sum);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement