borkins

Exam 24-Apr-2016 - 04. Smart Lilly

May 16th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. /**
  2.  * Project: Exam_24_April_2016 - created by borkins on 2017-05-15.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _04_SmartLilly
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.        
  13.         int age = Integer.parseInt(console.nextLine());
  14.         double priceWM = Double.parseDouble(console.nextLine());
  15.         int priceToy = Integer.parseInt(console.nextLine());
  16.        
  17.         int toys = 0;
  18.         double moneys = 0.0;
  19.        
  20.         for (int i = 1; i <= age; i++)
  21.         {
  22.             if (i % 2 == 0) {
  23.                 moneys += (i * 5) - 1;
  24.             }
  25.             else {
  26.                 toys++;
  27.             }
  28.         }
  29.        
  30.         moneys += (toys * priceToy);
  31.        
  32.         if (moneys >= priceWM) {
  33.             System.out.printf("Yes! %.2f%n", (moneys - priceWM));
  34.         }
  35.         else {
  36.             System.out.printf("No! %.2f%n", (priceWM - moneys));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment