package shop; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; /** * Requirement given to the agent, word for word: "Add a 10% discount for orders over Rs 1,000." * * THIS IS THE AGENT-STYLE FIRST DRAFT (written by Claude in this session to imitate a plausible agent reading * of that sentence). It compiles, and the tests it wrote for itself pass. It is also wrong. */ @Service public class PricingService { public record Quote(BigDecimal subtotal, BigDecimal shipping, BigDecimal discount, BigDecimal total) {} private static final BigDecimal THRESHOLD = new BigDecimal("1000"); private static final BigDecimal RATE = new BigDecimal("0.10"); public Quote quote(BigDecimal subtotal, BigDecimal shipping) { BigDecimal gross = subtotal.add(shipping); BigDecimal discount = gross.compareTo(THRESHOLD) >= 0 ? gross.multiply(RATE).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO.setScale(2); return new Quote(subtotal, shipping, discount, gross.subtract(discount).setScale(2, RoundingMode.HALF_UP)); } }