Advertisement
Lyubohd

Untitled

May 8th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_TouristShop {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scan.nextLine());
  8.         String product = scan.nextLine();
  9.         int counter = 0;
  10.         double moneySpend = 0.0;
  11.         while (!"Stop".equals(product)) {
  12.             double price = Double.parseDouble(scan.nextLine());
  13.             counter++;
  14.             if (counter % 3 == 0) {
  15.                 price /= 2.0;
  16.             }
  17.             if (price > budget) {
  18.                 System.out.println(String.format("You don't have enough money!%nYou need %.2f leva!", price - budget));
  19.                 break;
  20.             }
  21.             budget -= price;
  22.             moneySpend += price;
  23.             product = scan.nextLine();
  24.         }
  25.  
  26.         if ("Stop".equals(product)) {
  27.             System.out.println(String.format("You bought %d products for %.2f leva.", counter, moneySpend));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement