Advertisement
SvetlanPetrova

Clever Lilly SoftUni

Apr 25th, 2021
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 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.         int age = Integer.parseInt(scanner.nextLine());
  7.         double washingMachinePrice = Double.parseDouble(scanner.nextLine());
  8.         int toyPrice = Integer.parseInt(scanner.nextLine());
  9.  
  10.         int toyCount = 0;
  11.         double savedMoney = 0;
  12.         double moneyGift = 10;
  13.  
  14.  
  15.         for (int currentYear = 1; currentYear <= age; currentYear++) {
  16.             if (currentYear % 2 == 0) {
  17.                 savedMoney += (moneyGift - 1);
  18.                 moneyGift += 10;
  19.             }
  20.                 else {
  21.                 toyCount ++;
  22.             }
  23.         }
  24.  
  25.         double totalCash = (toyCount * toyPrice) + savedMoney;
  26.  
  27.         if (totalCash >= washingMachinePrice) {
  28.             System.out.printf("Yes! %.2f", totalCash - washingMachinePrice);
  29.         }
  30.         else {
  31.             System.out.printf("No! %.2f", washingMachinePrice - totalCash);
  32.         }
  33.  
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement