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