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.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());
}
}
}