import java.util.*;

public class Invoice {
    record Line(String item, int qty, double rate) { double amount() { return qty * rate; } }
    private final String customer;
    private final List<Line> lines = new ArrayList<>();
    Invoice(String customer) { this.customer = customer; }
    void add(String item, int qty, double rate) {
        if (qty <= 0) throw new IllegalArgumentException("Quantity must be positive");
        lines.add(new Line(item, qty, rate));
    }
    double taxable() { return lines.stream().mapToDouble(Line::amount).sum(); }
    double gst() { return Math.round(taxable() * 0.18 * 100) / 100.0; }
    public static void main(String[] args) {
        Invoice inv = new Invoice("Iyer Stores");
        inv.add("Laptop", 2, 42000); inv.add("Router", 3, 3400);
        Map<String, Double> byItem = new TreeMap<>();
        for (Line l : inv.lines) byItem.merge(l.item(), l.amount(), Double::sum);
        System.out.println(inv.customer + " " + byItem);
        System.out.printf("Taxable %.2f GST %.2f Total %.2f%n", inv.taxable(), inv.gst(), inv.taxable() + inv.gst());
    }
}
