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