diff --git a/src/main/java/ReportGenerator.java b/src/main/java/ReportGenerator.java index f5712ab..2431770 100644 --- a/src/main/java/ReportGenerator.java +++ b/src/main/java/ReportGenerator.java @@ -1,5 +1,6 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.FileWriter; import java.io.IOException; import java.util.List; import java.util.Scanner; @@ -82,25 +83,22 @@ public class ReportGenerator { public void saveReport() { - // TODO: - // 1. Build a formatted report string - // 2. Include: - // - total quantity - // - total final cost - // - total discount value - // - total invalid lines - // 3. Create/open output report file (name it report.txt) - // 4. Write report string into file - // 5. Handle file writing exceptions - // 6. Close writer resources - - /* Example Structure - ========= SALES REPORT ========= - Total Quantity Sold: 42 - Total Final Cost: $1520.75 - Total Discount Value: $230.50 - Invalid Rows: 3 - ================================ - */ + String report = + "===== SALES REPORT =====\n" + + "Total Quantity: " + totalQuantity + "\n" + + "Total Final Cost: $" + String.format("%.2f", totalFinalCost) + "\n" + + "Total Discount: $" + String.format("%.2f", totalDiscountValue) + "\n" + + "Invalid Lines: " + InvalidLines + "\n" + + "=========================\n"; + try + { + FileWriter fileWriter = new FileWriter("output.txt"); + fileWriter.write(report); + fileWriter.close(); + } + catch (IOException e) + { + System.out.println("Error in outputting report: " + e.getMessage()); + } } } \ No newline at end of file