Advertisement
stoyanoff

Vacation_Boyan

Jul 10th, 2020
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class Test {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         double wmoney = Double.parseDouble(scanner.nextLine());
  8.         double gotm = Double.parseDouble(scanner.nextLine());
  9.         int dayspend = 0;
  10.         int days = 0;
  11.  
  12.         while (dayspend < 5 && gotm < wmoney) {
  13.             String typo = scanner.nextLine();
  14.             double s = Double.parseDouble(scanner.nextLine());
  15.  
  16.             days += 1;
  17.             if (typo.equals("spend")) {
  18.                 dayspend += 1;
  19.                 gotm -= s;
  20.                 if (dayspend == 5) {
  21.                     break;
  22.  
  23.                 }
  24.                 if (gotm < 0) {
  25.                     gotm = 0;
  26.                 }
  27.             } else if (typo.equals("save")) {
  28.                 dayspend = 0;
  29.                 gotm += s;
  30.                 if (gotm >= wmoney) {
  31.                     break;
  32.                 }
  33.             }
  34. //            typo = scanner.nextLine();
  35. //            s = Integer.parseInt(scanner.nextLine());
  36.         }
  37.  
  38.  
  39.         if (gotm >= wmoney) {
  40.             System.out.printf("You saved the money for %d days.", days);
  41.         } else if (dayspend >= 5) {
  42.             System.out.printf("You can't save the money.\n%d", days);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement