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