Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Holidays_Money {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.print("Necessary money: ");
- double necessaryMoney = Double.parseDouble(keyboard.nextLine());
- System.out.print("Available money: ");
- double moneyAvailable = Double.parseDouble(keyboard.nextLine());
- int countAllDays = 0;
- int countSpendDays = 0;
- while (moneyAvailable <= necessaryMoney) {
- countAllDays++;
- System.out.print("Save or spend: ");
- String action = keyboard.nextLine();
- if (action.equalsIgnoreCase("save")) {
- System.out.println("How mush do you save: ");
- double savedMoney = Double.parseDouble(keyboard.nextLine());
- moneyAvailable = moneyAvailable + savedMoney;
- // System.out.println("You have " + moneyAvailable);
- }
- if (action.equalsIgnoreCase("spend")) {
- countSpendDays++;
- System.out.println("How much do you wanna spend: ");
- double spentMoney = Double.parseDouble(keyboard.nextLine());
- moneyAvailable -= spentMoney;
- } if (moneyAvailable < 0) {
- moneyAvailable = 0;
- System.out.println("You have " + moneyAvailable);
- }if (countSpendDays == 5) {
- System.out.printf("Yoy cannot save the necessary %.2f lv. %d days passed.%n",necessaryMoney,countSpendDays);
- System.out.println("You have " + moneyAvailable + "lv.");
- break;
- }
- System.out.println("You have " + moneyAvailable + "lv.");
- }
- if (moneyAvailable >= necessaryMoney) {
- System.out.printf("You saved the necessary %.2f lv. for %d days.", necessaryMoney, countAllDays);
- }
- }
- }
Add Comment
Please, Sign In to add comment