Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class U05Vacation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double moneyNeeded = Double.parseDouble(scanner.nextLine());
- double availableMoney = Double.parseDouble(scanner.nextLine());
- int spendingDays = 0;
- int totalDaysPassed = 0;
- while (moneyNeeded != availableMoney) {
- String input = scanner.nextLine();
- double amount = Double.parseDouble(scanner.nextLine());
- if (input.equals("spend")) {
- if (amount > availableMoney) {
- availableMoney = 0;
- spendingDays++;
- totalDaysPassed++;
- if (spendingDays >= 5) {
- System.out.printf("You can't save the money.%n");
- System.out.printf("%d", totalDaysPassed);
- break;
- }
- } else {
- availableMoney -= amount;
- spendingDays++;
- totalDaysPassed++;
- if (spendingDays >= 5) {
- System.out.printf("You can't save the money.%n");
- System.out.printf("%d", totalDaysPassed);
- break;
- }
- }
- } else {
- availableMoney += amount;
- spendingDays = 0;
- totalDaysPassed++;
- }
- } if (moneyNeeded <= availableMoney) {
- System.out.printf("You saved the money for %d days.", totalDaysPassed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement