From 2ef47e74597ef032f06e9b6b1ae8b5c3242e7794 Mon Sep 17 00:00:00 2001 From: Rafael Santos Date: Wed, 22 Aug 2018 20:37:03 -0300 Subject: [PATCH 1/3] fix code smells --- .../java/br/utfpr/tdd/ex1/EscritorCSV.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java b/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java index 6aec7ca..c29bb77 100644 --- a/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java +++ b/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java @@ -1,6 +1,7 @@ package br.utfpr.tdd.ex1; import java.io.BufferedWriter; +import java.io.IOException; import java.math.RoundingMode; import java.nio.file.Files; import java.nio.file.Paths; @@ -9,43 +10,48 @@ import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; + import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; /** - * * @author andreendo */ class EscritorCSV { CSVPrinter csvPrinter; - private final static Logger LOGGER = Logger.getLogger(EscritorCSV.class.getName()); - + private static final Logger LOGGER = Logger.getLogger(EscritorCSV.class.getName()); + void escrever(String ra, String nome, double notaFinal, String situacao) { try { - Locale locale = new Locale("en", "UK"); + Locale locale = new Locale("en", "UK"); DecimalFormat df = (DecimalFormat) - NumberFormat.getNumberInstance(locale); + NumberFormat.getNumberInstance(locale); df.applyPattern(".#"); df.setRoundingMode(RoundingMode.DOWN); csvPrinter.printRecord(ra, nome, df.format(notaFinal), situacao); - csvPrinter.flush(); - } - catch(Exception e) { + csvPrinter.flush(); + } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } void setArquivoSaida(String filePath) { + BufferedWriter writer = null; try { - BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath)); + writer = Files.newBufferedWriter(Paths.get(filePath)); csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT - .withHeader("RA", "Nome", "NF", "Situacao")); - csvPrinter.flush(); - } - catch(Exception e) { + .withHeader("RA", "Nome", "NF", "Situacao")); + csvPrinter.flush(); + } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); + } finally { + try { + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } - + } From 9c9ae07a8ebe03cff94c82c0f50ffe481994282f Mon Sep 17 00:00:00 2001 From: Rafael Santos Date: Wed, 22 Aug 2018 20:37:13 -0300 Subject: [PATCH 2/3] teste passando --- src/main/java/br/utfpr/tdd/ex1/Aluno.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/br/utfpr/tdd/ex1/Aluno.java b/src/main/java/br/utfpr/tdd/ex1/Aluno.java index 63588d7..3bd1930 100644 --- a/src/main/java/br/utfpr/tdd/ex1/Aluno.java +++ b/src/main/java/br/utfpr/tdd/ex1/Aluno.java @@ -44,8 +44,9 @@ void setNotaProjeto(double nota) { double getNF() { if(notaRAA < 0) return (notaProjeto + getNAP()) / 2.0; - - return (notaProjeto + getNAP() + notaRAA) / 3.0; + + double NF = (notaProjeto + getNAP() + notaRAA) / 3.0 ; + return NF > 6 ? 6 : NF; } void setNotaRAA(double nota) { From 6dd122f79834c69767f0596779df4f025f532349 Mon Sep 17 00:00:00 2001 From: Rafael Santos Date: Wed, 22 Aug 2018 20:44:32 -0300 Subject: [PATCH 3/3] teste csv passando --- src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java b/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java index c29bb77..fac93fe 100644 --- a/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java +++ b/src/main/java/br/utfpr/tdd/ex1/EscritorCSV.java @@ -36,21 +36,14 @@ void escrever(String ra, String nome, double notaFinal, String situacao) { } void setArquivoSaida(String filePath) { - BufferedWriter writer = null; try { - writer = Files.newBufferedWriter(Paths.get(filePath)); + BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath)); csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT .withHeader("RA", "Nome", "NF", "Situacao")); csvPrinter.flush(); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); - } finally { - try { - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } } }