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