Advertisement
damesova

Easter Shop [Mimi][Basics]

Apr 29th, 2019
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Tests {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.  
  7.         int initialEggAmount = Integer.parseInt(sc.nextLine());
  8.  
  9.         int soldEggs = 0;
  10.  
  11.         String command = "";
  12.         while (!"Close".equals(command = sc.nextLine())) {
  13.  
  14.             int amount = Integer.parseInt(sc.nextLine());
  15.  
  16.             switch (command) {
  17.                 case "Buy":
  18.                     soldEggs += amount;
  19.                     int eggsNow = initialEggAmount;
  20.                     initialEggAmount -= amount;
  21.                     if (initialEggAmount < 0) {
  22.                         System.out.println("Not enough eggs in store!");
  23.                         System.out.printf("You can buy only %d.%n", Math.abs(eggsNow));
  24.                         return;
  25.                     }
  26.                     break;
  27.                 case "Fill":
  28.                     initialEggAmount += amount;
  29.                     break;
  30.             }
  31.         }
  32.  
  33.         System.out.println("Store is closed!");
  34.         System.out.printf("%d eggs sold.%n", soldEggs);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement