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