Advertisement
finderabc

LiLis_Gifts

Feb 13th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LiLis_Gifts {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner key = new Scanner(System.in);
  7.         System.out.print("age: ");
  8.         int age = Integer.parseInt(key.nextLine());
  9.         System.out.print("toys' price: ");
  10.         int toyPrice = Integer.parseInt(key.nextLine());
  11.         System.out.print("wash machine price: ");
  12.         int machinePrice = Integer.parseInt(key.nextLine());
  13.         int moneyTimes = 0;
  14.         int sumByMoney = 0;
  15.         int remainingSum = 0;
  16.         int toys = 0;
  17.         for (int i = 1; i <= age; i++) {
  18.             if (i % 2 == 0) {
  19.                 moneyTimes++;
  20.                sumByMoney += moneyTimes * 10;  //sumByMoney = sumByMoney + (moneyTimes * 10);
  21.  
  22.                 remainingSum = sumByMoney - moneyTimes;
  23.             } else {
  24.                 toys++;
  25.             }
  26.         }
  27.       //  System.out.println("Times money received: " + moneyTimes);
  28.        // System.out.println("Total cash: " + sumByMoney);
  29.       //  System.out.println("Remained sum after brother's pinches: " + remainingSum);
  30.       //  System.out.printf("The sum by toys sell: %d lv.%n", toyPrice * toys);
  31.         System.out.println("--------------------------------------------------");
  32.         int totalSum = remainingSum + (toyPrice * toys);
  33.         System.out.printf("Total sum: %d lv.%n", totalSum);
  34.         System.out.println("--------------------------------------------------");
  35.         if (totalSum >= machinePrice){
  36.             System.out.printf("Yes, Lily can buy the wash machine. She will remain %d lv.", totalSum - machinePrice);
  37.         } else {
  38.             System.out.printf("No, Lily can't buy the wash machine. She is short of %d lv.", machinePrice - totalSum);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement