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());
- String product = "";
- double productPrice = 0;
- int productCount= 0;
- double totalPrice=0;
- while (!product.equals("Stop")){
- product = scanner.nextLine();
- if (product.equals("Stop")) {
- System.out.printf("You bought %d products for %.2f leva.", productCount, totalPrice);
- break;
- }
- productPrice = Double.parseDouble(scanner.nextLine());
- productCount ++;
- if (productCount %3==0){
- productPrice = productPrice/2;
- }
- totalPrice = totalPrice+productPrice;
- budget=budget-productPrice;
- if (budget<=0){
- System.out.println("You don't have enough money!");
- System.out.printf("You need %.2f leva!", Math.abs(budget));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement