Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ProgrammingBasics;
- import java.util.Scanner;
- public class Vacantion {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int moneyForVacantion = Integer.parseInt(scanner.nextLine());
- int availableMoney = Integer.parseInt(scanner.nextLine());
- int counterDays = 0;
- int counterMoney = 0;
- while (true) {
- String action = scanner.nextLine();
- int amountInAction = Integer.parseInt(scanner.nextLine());
- counterDays++;
- if (action.equals("spend")) {
- if (amountInAction > availableMoney) {
- availableMoney = 0;
- } else {
- availableMoney -= amountInAction;
- }
- counterMoney++;
- }
- if (counterMoney >= 5) {
- System.out.println("You can't save the money.");
- System.out.printf("%d", counterDays);
- break;
- } else if (action.equals("save")) {
- counterMoney = 0;
- availableMoney += amountInAction;
- if (availableMoney >= moneyForVacantion) {
- System.out.printf("You saved the money for %d days.", counterDays);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement