Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P04_TouristShop {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double budget = Double.parseDouble(scan.nextLine());
- String product = scan.nextLine();
- int counter = 0;
- double moneySpend = 0.0;
- while (!"Stop".equals(product)) {
- double price = Double.parseDouble(scan.nextLine());
- counter++;
- if (counter % 3 == 0) {
- price /= 2.0;
- }
- if (price > budget) {
- System.out.println(String.format("You don't have enough money!%nYou need %.2f leva!", price - budget));
- break;
- }
- budget -= price;
- moneySpend += price;
- product = scan.nextLine();
- }
- if ("Stop".equals(product)) {
- System.out.println(String.format("You bought %d products for %.2f leva.", counter, moneySpend));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement