Advertisement
yovkovbpfps

EXAM 20 - 21 APRIL Easter Guest

Apr 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EasterGuest {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int singleCakePrice = 4;
  8. double singleEggPrice = 0.45;
  9. double peopleCount = Integer.parseInt(scanner.nextLine());
  10. int budget = Integer.parseInt(scanner.nextLine());
  11.  
  12. double cakeCount = Math.ceil(peopleCount / 3);
  13. double eggsCount = peopleCount * 2;
  14. double cakePrice = singleCakePrice * cakeCount;
  15. double eggPrice = singleEggPrice * eggsCount;
  16. double total = cakePrice + eggPrice;
  17. String cakes = Integer.toString((int)cakeCount);
  18. String eggs = Integer.toString((int)eggsCount);
  19.  
  20. if (budget >= total){
  21. System.out.printf("Lyubo bought %s Easter bread and %s eggs.\n",cakes,eggs);
  22. double leftMoney = budget - total;
  23. System.out.printf("He has %.2f lv. left.", leftMoney);
  24. } else {
  25. System.out.printf("Lyubo doesn't have enough money.\n");
  26. double neededMoney = Math.abs(total-budget);
  27. System.out.printf("He needs %.2f lv. more.",neededMoney);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement