Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class ItIsChocolateTime {
- public static void main(String[] args) {
- Scanner myScan = new Scanner(System.in);
- ArrayDeque<Double> milkQuantities = Arrays.stream(myScan.nextLine().split(" "))
- .map(Double::parseDouble).collect(Collectors.toCollection(ArrayDeque::new));
- ArrayDeque<Double> cocoaPowderQuantities = new ArrayDeque<>();
- String[] cocoaPQasArray = myScan.nextLine().split(" ");
- for (int i = 0; i < cocoaPQasArray.length; i++) {
- cocoaPowderQuantities.push(Double.parseDouble(cocoaPQasArray[i]));
- }
- Map<String, Integer> chocolates = new TreeMap<>();
- while (!(milkQuantities.isEmpty() ||cocoaPowderQuantities.isEmpty())) {
- double milkQuantity = milkQuantities.poll();
- double cocoaPowderQuantity = cocoaPowderQuantities.pop();
- double cacaoPercentage = cocoaPowderQuantity / (cocoaPowderQuantity + milkQuantity);
- String kind = getKind(cacaoPercentage);
- if (!kind.equals("")) {
- chocolates.putIfAbsent(kind,0);
- chocolates.put(kind, chocolates.get(kind) + 1);
- }else{
- milkQuantities.offer(milkQuantity+10);
- }
- }
- if (checkPreparedAll(chocolates)){
- System.out.println("It’s a Chocolate Time. All chocolate types are prepared.");
- }else{
- System.out.println("Sorry, but you didn't succeed to prepare all types of chocolates.");
- }
- for (Map.Entry<String, Integer> chocolate : chocolates.entrySet()) {
- System.out.printf("# %s --> %d\n",chocolate.getKey(),chocolate.getValue());
- }
- }
- private static boolean checkPreparedAll(Map<String, Integer> chocolates) {
- return chocolates.size()==3;
- }
- private static String getKind(double cacaoPercentage) {
- if (cacaoPercentage == 0.3) {
- return "Milk Chocolate";
- } else if (cacaoPercentage == 0.5) {
- return "Dark Chocolate";
- } else if (cacaoPercentage == 1) {
- return "Baking Chocolate";
- }
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement