Advertisement
Spocoman

Easter Shop

Sep 5th, 2024 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 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.         int availableEggs = Integer.parseInt(scanner.nextLine()),
  7.                 eggs, soldEggs = 0;
  8.         String input;
  9.         while (!(input = scanner.nextLine()).equals("Close")) {
  10.             eggs = Integer.parseInt(scanner.nextLine());
  11.             if (input.equals("Buy")) {
  12.                 if (availableEggs - eggs < 0) {
  13.                     break;
  14.                 }
  15.                 availableEggs -= eggs;
  16.                 soldEggs += eggs;
  17.             } else if (input.equals("Fill")) {
  18.                 availableEggs += eggs;
  19.             }
  20.         }
  21.  
  22.         if (input.equals("Close")) {
  23.             System.out.println("Store is closed!\n" + soldEggs + " eggs sold.");
  24.         } else {
  25.             System.out.println("Not enough eggs in store!\nYou can buy only " + availableEggs + ".");
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement