Advertisement
IvaAnd

CleverLilly

Mar 5th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CleverLilly {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int lillyAge = Integer.parseInt(scanner.nextLine());
  8.         double washingMachine = Double.parseDouble(scanner.nextLine());
  9.         int toyPrice = Integer.parseInt(scanner.nextLine());
  10.         int evenYears = 0;
  11.         int oddYears = 0;
  12.         int moneyEvenYears = 0;
  13.  
  14.         // odd years -> toy
  15.         // even years -> money 10lv for first and 10lv more for every next
  16.         //Lilly brother cheat with 1 lv for each money year
  17.         // lilly sll toys for for numberOfToys * toyPrice
  18.         // if enough left = total - washing machine price
  19.         // if not enough = washing machine - total
  20.  
  21.         for (int years = 1; years <= lillyAge; years++) {
  22.  
  23.             if (years % 2 == 0) {
  24.                 evenYears++;
  25.                 moneyEvenYears = (evenYears * 10) + moneyEvenYears;
  26.  
  27.             } else {
  28.                 oddYears++;
  29.             }
  30.             // deduct 1 lv for each even year, brother cheat
  31.         }
  32.         int netMoney = moneyEvenYears - evenYears;
  33.         int moneyFromToys = oddYears * toyPrice;
  34.         int totalSaved = netMoney + moneyFromToys;
  35.  
  36.         if ( totalSaved> washingMachine){
  37.             double left = totalSaved - washingMachine;
  38.             System.out.printf("Yes! %.2f", left);
  39.         } else {
  40.             double need = washingMachine - totalSaved;
  41.             System.out.printf("No! %.2f", need);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement