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 tripPrice = Double.parseDouble(scanner.nextLine());
- double savedMoney = Double.parseDouble(scanner.nextLine());
- String action = scanner.nextLine();
- double sum = Double.parseDouble(scanner.nextLine());
- int daysCounter = 0;
- int spendCounter = 0;
- while (savedMoney < tripPrice) {
- daysCounter++;
- if (action.equals("spend")) {
- savedMoney -= sum;
- spendCounter++;
- if (savedMoney < 0) {
- savedMoney = 0;
- }
- if (spendCounter == 5) {
- System.out.printf("You can't save the money.%n%d", spendCounter);
- break;
- }
- } else if (action.equals("save")) {
- savedMoney += sum;
- if (savedMoney < 0) {
- savedMoney = 0;
- }
- }
- if (savedMoney >= tripPrice) {
- System.out.printf("You saved the money for %d days.", daysCounter);
- break;
- }
- action = scanner.nextLine();
- sum = Double.parseDouble(scanner.nextLine());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement