Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- double bill = 2.50;
- int items = 0;
- while (true) {
- String nameOfTheProduct = scanner.nextLine();
- if (nameOfTheProduct.equalsIgnoreCase("Order"))
- break;
- double priceProduct = Double.parseDouble(scanner.nextLine());
- if (budget >= bill) {
- bill += priceProduct;
- items++;
- }
- if (bill > budget) {
- bill -= priceProduct;
- items--;
- System.out.println("You will exceed the budget if you order this!");
- }
- }
- if (budget >= bill) {
- System.out.printf("You ordered %d items!%n", items);
- System.out.printf("Total: %.2f%n", bill);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement