Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TouristShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- int counter = 0;
- int productCount = 0;
- boolean isDone = false;
- double sum = 0;
- String command = scanner.nextLine();
- while (!"Stop".equals(command)) {
- counter++;
- String productName = command;
- double priceProduct = Double.parseDouble(scanner.nextLine());
- productCount++;
- if (counter == 3) {
- priceProduct /= 2;
- counter = 0;
- }
- sum += priceProduct;
- budget -= priceProduct;
- if (budget < priceProduct) {
- isDone = true;
- break;
- }
- command = scanner.nextLine();
- }
- if (isDone) {
- System.out.println("You don't have enough money!");
- System.out.printf("You need %.2f leva!", Math.abs(budget));
- } else {
- System.out.printf("You bought %d products for %.2f leva.", productCount, sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement