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