completing saveReport() function.

This commit is contained in:
2026-07-17 00:28:00 +03:30
parent 3763ddd3ab
commit c07c5caf52
+18 -20
View File
@@ -1,5 +1,6 @@
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
@@ -82,25 +83,22 @@ public class ReportGenerator {
public void saveReport() public void saveReport()
{ {
// TODO: String report =
// 1. Build a formatted report string "===== SALES REPORT =====\n" +
// 2. Include: "Total Quantity: " + totalQuantity + "\n" +
// - total quantity "Total Final Cost: $" + String.format("%.2f", totalFinalCost) + "\n" +
// - total final cost "Total Discount: $" + String.format("%.2f", totalDiscountValue) + "\n" +
// - total discount value "Invalid Lines: " + InvalidLines + "\n" +
// - total invalid lines "=========================\n";
// 3. Create/open output report file (name it report.txt) try
// 4. Write report string into file {
// 5. Handle file writing exceptions FileWriter fileWriter = new FileWriter("output.txt");
// 6. Close writer resources fileWriter.write(report);
fileWriter.close();
/* Example Structure }
========= SALES REPORT ========= catch (IOException e)
Total Quantity Sold: 42 {
Total Final Cost: $1520.75 System.out.println("Error in outputting report: " + e.getMessage());
Total Discount Value: $230.50 }
Invalid Rows: 3
================================
*/
} }
} }