Lyutov02

SmartLilly

Nov 30th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SmartLilly {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         System.out.print("Enter Lilly's age: ");
  9.         int age = Integer.parseInt(sc.nextLine());
  10.         System.out.print("Enter the price of the washing machine: ");
  11.         double priceOfWashingMachine = Double.parseDouble(sc.nextLine());
  12.         System.out.print("Enter the price for toys: ");
  13.         int presentPrice = Integer.parseInt(sc.nextLine());
  14.  
  15.         int numberOfToys = 0;
  16.         int savedMoney = 0;
  17.         int moneyForBirthday = 10;
  18.  
  19.         for (int currentYear = 1; currentYear <= age; currentYear++) {
  20.             if (currentYear % 2 == 0) {
  21.                 savedMoney += (moneyForBirthday - 1);
  22.                 moneyForBirthday += 10;
  23.             } else {
  24.                 numberOfToys++;
  25.             }
  26.         }
  27.  
  28.         savedMoney += numberOfToys * presentPrice;
  29.  
  30.         System.out.println((savedMoney >= priceOfWashingMachine) ?
  31.                 String.format("Yes! %.2f", (savedMoney - priceOfWashingMachine))
  32.                 : String.format("No! %.2f", (priceOfWashingMachine - savedMoney)));
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment