Add discount calculation

Problem Context

E-commerce checkout needs to apply percentage discounts and calculate final totals.

Intermediate
100 points

File Changes (1)

src/main/java/com/example/service/DiscountService.java MODIFIED
@@ -15 +15 @@
15 15 @Service
16 16 public class DiscountService {
17 +
18 + public double calculateFinalPrice(double originalPrice, double discountPercent) {
19 + double discountAmount = originalPrice * (discountPercent / 100.0);
20 + return originalPrice - discountAmount;
21 + }
22 +
23 + public double calculateCartTotal(List<CartItem> items) {
24 + double total = 0.0;
25 + for (CartItem item : items) {
26 + total += item.getPrice() * item.getQuantity();
27 + }
28 + return total;
29 + }
30 +
31 + public boolean isPriceMatch(double price1, double price2) {
32 + return price1 == price2;
33 + }
17 34 }
Login Required: You must be registered to submit reviews and receive AI feedback. Register or login to start reviewing!

Your Review

Tip: Be thorough! Consider security, performance, code quality, and best practices.
Review Tips
  • Look for security vulnerabilities (SQL injection, XSS, etc.)
  • Check for null pointer exceptions and error handling
  • Consider performance implications
  • Evaluate code maintainability and readability
  • Check for proper resource management
  • Look for logic errors or edge cases
Analyzing Your Review
Our AI is carefully evaluating your code review against best practices