ventsislav83

smartLily

Jun 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public class smartLily {
  2.  
  3.     public static void main(String[] args) {
  4.         Scanner input = new Scanner(System.in);
  5.         int age = Integer.parseInt(input.nextLine());
  6.         double washingMachinePrice = Double.parseDouble(input.nextLine());
  7.         int toyPrice = Integer.parseInt(input.nextLine());
  8.         int totalToysCollected=0;
  9.         double moneySaved=0;
  10.         for (int i = 1; i <= age; i++) {
  11.             if(i%2==1){
  12.             totalToysCollected++;
  13.             }else{
  14.             moneySaved+=i/2*10;
  15.             moneySaved-=1.00;
  16.             }
  17.         }
  18.         double totalToysPrice = totalToysCollected*toyPrice;
  19.         double totalMoney=totalToysPrice+moneySaved;
  20.         if(washingMachinePrice<=totalMoney){
  21.             double leftover=totalMoney-washingMachinePrice;
  22.             System.out.printf("Yes! %.2f",leftover);
  23.         }else{
  24.             double notEnoughMoney=washingMachinePrice-totalMoney;
  25.             System.out.printf("No! %.2f",notEnoughMoney);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment