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