Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EasterGuest {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int singleCakePrice = 4;
- double singleEggPrice = 0.45;
- double peopleCount = Integer.parseInt(scanner.nextLine());
- int budget = Integer.parseInt(scanner.nextLine());
- double cakeCount = Math.ceil(peopleCount / 3);
- double eggsCount = peopleCount * 2;
- double cakePrice = singleCakePrice * cakeCount;
- double eggPrice = singleEggPrice * eggsCount;
- double total = cakePrice + eggPrice;
- String cakes = Integer.toString((int)cakeCount);
- String eggs = Integer.toString((int)eggsCount);
- if (budget >= total){
- System.out.printf("Lyubo bought %s Easter bread and %s eggs.\n",cakes,eggs);
- double leftMoney = budget - total;
- System.out.printf("He has %.2f lv. left.", leftMoney);
- } else {
- System.out.printf("Lyubo doesn't have enough money.\n");
- double neededMoney = Math.abs(total-budget);
- System.out.printf("He needs %.2f lv. more.",neededMoney);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement