Advertisement
stoyanoff

SmartLilly

Jul 1st, 2020
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SmartLilly {
  6.     public static void main(String[] args) {
  7.         Scanner myScan = new Scanner(System.in);
  8.  
  9.         int ageLilly = Integer.parseInt(myScan.nextLine());
  10.         double washingMachinePrice = Double.parseDouble(myScan.nextLine());
  11.         int toyPrice = Integer.parseInt(myScan.nextLine());
  12.         int toysCount = 0;
  13.         int moneyPerYear = 0;
  14.         int moneyCollected = 0;
  15.         int brotherMoney = 0;
  16.  
  17.         for (int i = 1; i <= ageLilly; i++) {
  18.  
  19.             if (i % 2 == 0) {
  20.                 moneyPerYear += 10;
  21.                 moneyCollected += moneyPerYear;
  22.                 brotherMoney++;
  23.             } else {
  24.                 toysCount += 1;
  25.             }
  26.         }
  27.         double totalMoney = moneyCollected + (toyPrice * toysCount) - brotherMoney;
  28.  
  29.         if (totalMoney >= washingMachinePrice) {
  30.             double remainMoney = totalMoney - washingMachinePrice;
  31.             System.out.printf("Yes! %.2f", remainMoney);
  32.         } else {
  33.             double neededMoney = washingMachinePrice - totalMoney;
  34.             System.out.printf("No! %.2f", neededMoney);
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement