Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class E06CottageScraper {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- List<Tree> list = new ArrayList<>();
- String command = sc.nextLine();
- while (!command.equals("chop chop")) {
- String[] input = command.split(" -> ");
- String type = input[0];
- int meters = Integer.parseInt(input[1]);
- Tree tree = new Tree(type, meters);
- list.add(tree);
- command = sc.nextLine();
- }
- String neededType = sc.nextLine();
- double minMeters = Double.parseDouble(sc.nextLine());
- double usedLogsSum = list.stream().filter(tree -> tree.getType().equals(neededType) && tree.getLength() >= minMeters).mapToDouble(Tree::getLength).sum();
- double unusedLogsSum = list.stream().filter(tree -> !tree.getType().equals(neededType) || tree.getLength() < minMeters).mapToDouble(Tree::getLength).sum();
- double priceToRound = list.stream().mapToDouble(Tree::getLength).average().orElse(0.0);
- double price = Math.round(priceToRound * 100.0) / 100.0;
- double usedLogsPrice = Math.round(usedLogsSum * price * 100.0) / 100.0;
- double unusedLogsPrice = Math.round((unusedLogsSum * price * 0.25) * 100.0) / 100.0;
- double total = Math.round((usedLogsPrice + unusedLogsPrice) * 100.0) / 100.0;
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement