Advertisement
Guest User

Untitled

a guest
Oct 29th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BakingMasterclass {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         int students = Integer.parseInt(scanner.nextLine());
  9.         double priceOfFlour = Double.parseDouble(scanner.nextLine());
  10.         double priceOfEgg = Double.parseDouble(scanner.nextLine());
  11.         double priceOfApron = Double.parseDouble(scanner.nextLine());
  12.  
  13.         //count of aprons should be 20% more, rounded up to the next integer
  14.         int countOfArons = (int) Math.ceil(students * 1.2);
  15.        
  16.         //every fifth package of flour is free.
  17.         int freePackages = students / 5;
  18.  
  19.         double neededMoney = priceOfApron * countOfArons +
  20.                 priceOfEgg * 10 * students +
  21.                 priceOfFlour * (students - freePackages);
  22.  
  23.         if (neededMoney <= budget) {
  24.             System.out.printf("Items purchased for %.2f$.", neededMoney);
  25.         } else {
  26.             System.out.printf("%.2f$ more needed.", neededMoney - budget);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement