Advertisement
damesova

Clever Lily [Mimi][PB]

May 22nd, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CleverLily {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int age = Integer.parseInt(scanner.nextLine());
  7.         double washPrice = Double.parseDouble(scanner.nextLine());
  8.         double toyPrice = Double.parseDouble(scanner.nextLine());
  9.  
  10.         int savings = 0;
  11.         int toyCount = 0;
  12.         int brotherShare = 0;
  13.  
  14.         for (int year = 1; year <= age; year++) {
  15.             if (year % 2 == 0) { // money
  16.                 savings += year *10 / 2;
  17.                 brotherShare++;
  18.             } else { // toy
  19.                 toyCount++;
  20.             }
  21.         }
  22.  
  23.         // add toys money to savings:
  24.         savings += toyCount * toyPrice;
  25.  
  26.         // -1 lv. for brother:
  27.         savings -= brotherShare;
  28.  
  29.         double diff = savings - washPrice;
  30.         if (diff >= 0) {
  31.             System.out.printf("Yes! %.2f",(diff));
  32.         } else {
  33.             System.out.printf("No! %.2f", Math.abs(diff));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement