public class E06CottageScraper { public static void main(String[] args) { Scanner sc = new Scanner(System.in); List list = new ArrayList<>(); String command = sc.nextLine(); while (!command.equals("chop chop")) { String[] input = command.split(" -> "); list.add(new Tree(input[0], Integer.parseInt(input[1]))); command = sc.nextLine(); } String neededType = sc.nextLine(); double minMeters = Double.parseDouble(sc.nextLine()); BigDecimal usedSum = new BigDecimal(0); BigDecimal unusedSum = new BigDecimal(0); for (Tree tree : list) { if (tree.getType().equals(neededType) && tree.getLength() >= minMeters) { usedSum = usedSum.add(BigDecimal.valueOf(tree.length)); } else { unusedSum = unusedSum.add(BigDecimal.valueOf(tree.length)); } } BigDecimal price = usedSum.add(unusedSum).divide(BigDecimal.valueOf(list.size()), 2, RoundingMode.HALF_EVEN); BigDecimal usedLogsPrice = price.multiply(usedSum).setScale(2, RoundingMode.HALF_EVEN); BigDecimal unusedLogsPrice = price.multiply(unusedSum).multiply(BigDecimal.valueOf(0.25)).setScale(2, BigDecimal.ROUND_HALF_EVEN); BigDecimal total = unusedLogsPrice.add(usedLogsPrice).setScale(2, BigDecimal.ROUND_HALF_EVEN); System.out.printf("Price per meter: $%.2f%n", price); System.out.printf("Used logs price: $%.2f%n", usedLogsPrice); System.out.printf("Unused logs price: $%.2f%n", unusedLogsPrice); System.out.printf("CottageScraper subtotal: $%.2f", total); } private static class Tree { String type; int length; private Tree(String type, int length) { this.type = type; this.length = length; } public String getType() { return type; } public int getLength() { return length; } } }