[POO] Simplification

This commit is contained in:
TiagoRG 2023-05-12 22:07:20 +01:00
parent 4f3c1a9f6d
commit 10959b710e
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 2 additions and 7 deletions

View File

@ -8,7 +8,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
public class EnergyUsageReport { public class EnergyUsageReport {
@ -48,13 +47,9 @@ public class EnergyUsageReport {
return MathTools.sum(getCustomer(id).getMeterReadings()); return MathTools.sum(getCustomer(id).getMeterReadings());
} }
public void generateReport(String path) { public void generateReport(String path) throws IOException {
for (Customer customer : customers) { for (Customer customer : customers) {
try { Files.writeString(Path.of(path), String.format("Customer ID: %d%nTotal usage: %.1f%n%n", customer.getCustomerId(), calculateTotalUsage(customer.getCustomerId())), (new File(path)).exists() ? java.nio.file.StandardOpenOption.APPEND : java.nio.file.StandardOpenOption.CREATE);
Files.writeString(Path.of(path), String.format("Customer ID: %d%nTotal usage: %.1f%n%n", customer.getCustomerId(), calculateTotalUsage(customer.getCustomerId())), (new File(path)).exists() ? java.nio.file.StandardOpenOption.APPEND : java.nio.file.StandardOpenOption.CREATE);
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
} }
} }