Advertisement
galinyotsev123

ProgBasicsExam12January2019-04FoodOrder

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