Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exam_Task4_EasterShop {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int eggsInStore = Integer.parseInt(scanner.nextLine());
- String command = scanner.nextLine();
- boolean outOfStock = false;
- int soldEggs = 0;
- while (!"Close".equals(command)) {
- int eggs = Integer.parseInt(scanner.nextLine());
- if ("Buy".equals(command)) {
- soldEggs += eggs;
- if (eggs > eggsInStore) {
- outOfStock = true;
- break;
- }
- eggsInStore -= soldEggs;
- }
- if ("Fill".equals(command)) {
- eggsInStore += eggs;
- }
- command = scanner.nextLine();
- }
- if (outOfStock) {
- System.out.printf("Not enough eggs in store!\nYou can buy only %d.", eggsInStore);
- } else {
- System.out.printf("Store is closed!\n%d eggs sold.", soldEggs);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement