Advertisement
Guest User

Untitled

a guest
May 18th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EasterShop {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int quantityEggs = Integer.parseInt(scanner.nextLine());
  8.         String command = scanner.nextLine();
  9.         int leftEggs = 0;
  10.         int soldEggs = 0;
  11.  
  12.         while (!command.equals("Close")) {
  13.  
  14.             int countEggs = Integer.parseInt(scanner.nextLine());
  15.            
  16.             if (command.equals("Buy")) {
  17.                 leftEggs = quantityEggs - countEggs;
  18.                 soldEggs += countEggs;
  19.  
  20.  
  21.             } else if (command.equals("Fill")) {
  22.                 leftEggs = quantityEggs + countEggs;
  23.                
  24.             }
  25.            
  26.             if (countEggs > leftEggs) {
  27.                 System.out.println("Not enough eggs in store!");
  28.                 System.out.printf("You can buy only %d.", leftEggs);
  29.                 break;
  30.             }
  31.  
  32.         }
  33.  
  34.         if (command.equals("Close")) {
  35.             System.out.println("Store is closed!");
  36.             System.out.printf("%d eggs sold.", soldEggs);
  37.  
  38.            
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement