Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BakingMasterclass {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- int students = Integer.parseInt(scanner.nextLine());
- double priceOfFlour = Double.parseDouble(scanner.nextLine());
- double priceOfEgg = Double.parseDouble(scanner.nextLine());
- double priceOfApron = Double.parseDouble(scanner.nextLine());
- //count of aprons should be 20% more, rounded up to the next integer
- int countOfArons = (int) Math.ceil(students * 1.2);
- //every fifth package of flour is free.
- int freePackages = students / 5;
- double neededMoney = priceOfApron * countOfArons +
- priceOfEgg * 10 * students +
- priceOfFlour * (students - freePackages);
- if (neededMoney <= budget) {
- System.out.printf("Items purchased for %.2f$.", neededMoney);
- } else {
- System.out.printf("%.2f$ more needed.", neededMoney - budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement