From 10959b710e3c3cdd5bad732eb63c97541791bac6 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Fri, 12 May 2023 22:07:20 +0100 Subject: [PATCH] [POO] Simplification --- 1ano/2semestre/poo/src/aula11/ex3/EnergyUsageReport.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/1ano/2semestre/poo/src/aula11/ex3/EnergyUsageReport.java b/1ano/2semestre/poo/src/aula11/ex3/EnergyUsageReport.java index f99fd2c..77ec61e 100644 --- a/1ano/2semestre/poo/src/aula11/ex3/EnergyUsageReport.java +++ b/1ano/2semestre/poo/src/aula11/ex3/EnergyUsageReport.java @@ -8,7 +8,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; -import java.util.Collections; import java.util.LinkedList; public class EnergyUsageReport { @@ -48,13 +47,9 @@ public class EnergyUsageReport { return MathTools.sum(getCustomer(id).getMeterReadings()); } - public void generateReport(String path) { + public void generateReport(String path) throws IOException { 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); - } catch (IOException e) { - throw new RuntimeException(e); - } + 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); } } }