SHARE
TWEET

Untitled

a guest May 27th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Easter {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int eggsCount = Integer.parseInt(scanner.nextLine());
  8.         int soldEggs = 0;
  9.  
  10.         String command = scanner.nextLine();
  11.         while (!"Close".equals(command)) {
  12.             if ("Fill".equals(command)) {
  13.                 int toFill = Integer.parseInt(scanner.nextLine());
  14.                 eggsCount += toFill;
  15.             }
  16.             if ("Buy".equals(command)) {
  17.                 int count = Integer.parseInt(scanner.nextLine());
  18.  
  19.                 if (count <= eggsCount) {
  20.                     eggsCount -= count;
  21.                     soldEggs += count;
  22.                 } else {
  23.                     System.out.println("Not enough eggs in store!");
  24.                     System.out.printf("You can buy only %d.", eggsCount);
  25.                     break;
  26.  
  27.                 }
  28.             }
  29.             command = scanner.nextLine();
  30.         }
  31.         if ("Close".equals(command)) {
  32.             System.out.println("Store is closed!");
  33.             System.out.printf("%d eggs sold.", eggsCount);
  34.         }
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top