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