Advertisement
sievrebo

Untitled

Apr 29th, 2019
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamEasterShop4 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int currentSumEggs = Integer.parseInt(scanner.nextLine());
  7. int soldEggs=0;
  8.  
  9.  
  10. String input = scanner.nextLine();
  11. while (!"Close".equals(input)) {
  12. int numEggs = Integer.parseInt(scanner.nextLine());
  13.  
  14. if ("Fill".equals(input)) {
  15. currentSumEggs += numEggs;
  16. } else if ("Buy".equals(input)) {
  17. if (currentSumEggs < numEggs) {
  18. System.out.printf("Not enough eggs in store!\nYou can buy only %d.", currentSumEggs);
  19. } else {
  20. currentSumEggs -= numEggs;
  21. }
  22. soldEggs+=numEggs;
  23. }
  24. input = scanner.nextLine();
  25. }
  26. System.out.printf("Store is closed!\n%d eggs sold.", soldEggs);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement