Advertisement
IngersollRand

Untitled

Apr 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exam_Task4_EasterShop {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int eggsInStore = Integer.parseInt(scanner.nextLine());
  9. String command = scanner.nextLine();
  10.  
  11. boolean outOfStock = false;
  12.  
  13. int soldEggs = 0;
  14. while (!"Close".equals(command)) {
  15. int eggs = Integer.parseInt(scanner.nextLine());
  16.  
  17. if ("Buy".equals(command)) {
  18. soldEggs += eggs;
  19.  
  20. if (eggs > eggsInStore) {
  21. outOfStock = true;
  22. break;
  23. }
  24. eggsInStore -= soldEggs;
  25. }
  26. if ("Fill".equals(command)) {
  27. eggsInStore += eggs;
  28. }
  29.  
  30. command = scanner.nextLine();
  31. }
  32. if (outOfStock) {
  33. System.out.printf("Not enough eggs in store!\nYou can buy only %d.", eggsInStore);
  34. } else {
  35. System.out.printf("Store is closed!\n%d eggs sold.", soldEggs);
  36. }
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement