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