Advertisement
Sim0o0na

CleverLily

Jul 6th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CleverLily {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int age = Integer.parseInt(scanner.nextLine());
  10. double washingMachinePrice = Double.parseDouble(scanner.nextLine());
  11. int singleToyPrice = Integer.parseInt(scanner.nextLine());
  12.  
  13. int toysCount = 0;
  14. int moneyGiven = 10;
  15. int savings = 0;
  16. for (int birthday = 1; birthday <= age; birthday++) {
  17.  
  18. if (birthday % 2 == 1) {
  19. toysCount++;
  20. } else {
  21. savings += moneyGiven;
  22. moneyGiven += 10;
  23. savings -= 1; // savings = savings - 1
  24. }
  25. }
  26.  
  27. int profitFromToys = toysCount * singleToyPrice;
  28. savings += profitFromToys;
  29.  
  30. if (savings >= washingMachinePrice) {
  31. System.out.printf("Yes! %.2f", savings - washingMachinePrice);
  32. } else {
  33. System.out.printf("No! %.2f", washingMachinePrice - savings);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement