daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Practise {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double moneyNeeded = Double.parseDouble(scanner.nextLine());
  8.         double avaibleMoney = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int spendCounter = 0;
  11.         int dayCounter = 0;
  12.  
  13.         while (avaibleMoney < moneyNeeded) {
  14.             String action = scanner.nextLine();
  15.             double sum = Double.parseDouble(scanner.nextLine());
  16.  
  17.             dayCounter++;
  18.             if ("spend".equals(action)) {
  19.                 spendCounter++;
  20.                 if (spendCounter == 5) {
  21.                     System.out.printf("You can't save the money.%n%d", dayCounter);
  22.                     return;
  23.                 } else {
  24.                     avaibleMoney -= sum;
  25.                     if (avaibleMoney < sum) {
  26.                         avaibleMoney = 0;
  27.                     }
  28.                 }
  29.             } else if ("save".equals(action)) {
  30.                 spendCounter = 0;
  31.                 avaibleMoney += sum;
  32.             }
  33.         }
  34.         if (avaibleMoney >= moneyNeeded) {
  35.             System.out.printf("You saved the money for %d days.", dayCounter);
  36.         }
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top