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