Advertisement
IrinaIgnatova

Cooking Masterclass

Jun 29th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.List;
  7. import java.util.Scanner;
  8.  
  9. public class Main {
  10.  
  11.     public static void main(String[] args) {
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.  
  15.         double budget = Double.parseDouble(scanner.nextLine());
  16.  
  17.         int students = Integer.parseInt(scanner.nextLine());
  18.  
  19.         double pricePackageFlour = Double.parseDouble(scanner.nextLine());
  20.  
  21.         double priceSingleEgg = Double.parseDouble(scanner.nextLine());
  22.         double priceOneApron = Double.parseDouble(scanner.nextLine());
  23.  
  24.  
  25.         double priceSetStudent = pricePackageFlour + 10 * priceSingleEgg + priceOneApron;
  26.         double priceSetAllStudents = 0;
  27.         double additionalCountAprons = Math.ceil(0.2 * students);
  28.         //System.out.println(countAprons);
  29.  
  30.         for (int i = 1; i <= students; i++) {
  31.             if (i % 5 == 0) {
  32.                 priceSetStudent = 10 * priceSingleEgg + priceOneApron;
  33.  
  34.             } else {
  35.                 priceSetStudent = pricePackageFlour + 10 * priceSingleEgg + priceOneApron;
  36.             }
  37.             priceSetAllStudents += priceSetStudent;
  38.  
  39.  
  40.         }
  41.         double sumNeeded = priceSetAllStudents + (additionalCountAprons * priceOneApron);
  42.  
  43.  
  44.         if (sumNeeded <= budget) {
  45.             System.out.printf("Items purchased for %.2f$.", sumNeeded);
  46.         } else if (sumNeeded > budget) {
  47.             double moneyNotEnough = sumNeeded - budget;
  48.             System.out.printf("%.2f$ more needed.", moneyNotEnough);
  49.  
  50.         }
  51.  
  52.  
  53.     }
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement