Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.function.DoubleUnaryOperator;
- public class Vacation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Double holidayMoney = Double.parseDouble(scanner.nextLine());
- Double ownedMoney = Double.parseDouble(scanner.nextLine());
- Integer counterSpend = 0;
- Integer counter = 0;
- while(ownedMoney < holidayMoney){
- String operation = scanner.nextLine();
- Double amount = Double.parseDouble(scanner.nextLine());
- if("spend".equals(operation)){
- ownedMoney -= amount;
- counterSpend += 1;
- counter += 1;
- if(counterSpend >= 5){
- System.out.println("You can't save the money.");
- System.out.println(counter);
- break;
- }else {}
- if(ownedMoney < 0.00){
- ownedMoney = 0.00;
- }else {}
- }else{
- ownedMoney += amount;
- counterSpend = 0;
- counter += 1;
- }
- }
- if(ownedMoney >= holidayMoney){
- System.out.printf("You saved the money for %d days.", counter);
- }
- }
- }
Add Comment
Please, Sign In to add comment