Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package Exam12January2019;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class FoodOrder {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. double budget = Double.parseDouble(scanner.nextLine());
  9. double priceOrder = Double.parseDouble(scanner.nextLine());
  10. int counterItems = 0;
  11. while (priceOrder <= budget) {
  12. String nameProduct = scanner.nextLine();
  13. if (nameProduct.equals("Order")) {
  14. break;
  15. }
  16. double priceProduct = Double.parseDouble(scanner.nextLine());
  17. priceOrder += priceProduct;
  18. if (priceOrder > budget) {
  19. priceOrder -= priceProduct;
  20. System.out.println("You will exceed the budget if you order this!");
  21. } else {
  22. counterItems++;
  23. }
  24. }
  25. System.out.printf("You ordered %d items!%n", counterItems);
  26. System.out.printf("Total: %.2f", priceOrder);
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement