diff --git a/1ano/2semestre/c2/fichas/enunciados/f4_EDO_2223.pdf b/1ano/2semestre/c2/fichas/enunciados/f4_EDO_2223.pdf new file mode 100644 index 0000000..07e9d6a Binary files /dev/null and b/1ano/2semestre/c2/fichas/enunciados/f4_EDO_2223.pdf differ diff --git a/1ano/2semestre/c2/fichas/solucoes/f4_EDO_2223_sol.pdf b/1ano/2semestre/c2/fichas/solucoes/f4_EDO_2223_sol.pdf new file mode 100644 index 0000000..3c8593f Binary files /dev/null and b/1ano/2semestre/c2/fichas/solucoes/f4_EDO_2223_sol.pdf differ diff --git a/1ano/2semestre/c2/slides/EDO_22_23.pdf b/1ano/2semestre/c2/slides/EDO_22_23.pdf new file mode 100644 index 0000000..3ba26ce Binary files /dev/null and b/1ano/2semestre/c2/slides/EDO_22_23.pdf differ diff --git a/1ano/2semestre/md/fichas/folha0_MD_2023.pdf b/1ano/2semestre/md/fichas/fichas/folha0_MD_2023.pdf similarity index 100% rename from 1ano/2semestre/md/fichas/folha0_MD_2023.pdf rename to 1ano/2semestre/md/fichas/fichas/folha0_MD_2023.pdf diff --git a/1ano/2semestre/md/fichas/folha1_MD_2023.pdf b/1ano/2semestre/md/fichas/fichas/folha1_MD_2023.pdf similarity index 100% rename from 1ano/2semestre/md/fichas/folha1_MD_2023.pdf rename to 1ano/2semestre/md/fichas/fichas/folha1_MD_2023.pdf diff --git a/1ano/2semestre/md/fichas/fichas/folha2_MD_2023.pdf b/1ano/2semestre/md/fichas/fichas/folha2_MD_2023.pdf new file mode 100644 index 0000000..c13f777 Binary files /dev/null and b/1ano/2semestre/md/fichas/fichas/folha2_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/fichas/folha3_MD_2023.pdf b/1ano/2semestre/md/fichas/fichas/folha3_MD_2023.pdf new file mode 100644 index 0000000..2a7290d Binary files /dev/null and b/1ano/2semestre/md/fichas/fichas/folha3_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/fichas/folha4_MD_2023.pdf b/1ano/2semestre/md/fichas/fichas/folha4_MD_2023.pdf new file mode 100644 index 0000000..b683c69 Binary files /dev/null and b/1ano/2semestre/md/fichas/fichas/folha4_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folha_semana01_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana01_MD_2023.pdf similarity index 100% rename from 1ano/2semestre/md/fichas/folha_semana01_MD_2023.pdf rename to 1ano/2semestre/md/fichas/folhas_semana/folha_semana01_MD_2023.pdf diff --git a/1ano/2semestre/md/fichas/folha_semana02_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana02_MD_2023.pdf similarity index 100% rename from 1ano/2semestre/md/fichas/folha_semana02_MD_2023.pdf rename to 1ano/2semestre/md/fichas/folhas_semana/folha_semana02_MD_2023.pdf diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana03_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana03_MD_2023.pdf new file mode 100644 index 0000000..8557bcf Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana03_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana04_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana04_MD_2023.pdf new file mode 100644 index 0000000..a334003 Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana04_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana05_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana05_MD_2023.pdf new file mode 100644 index 0000000..bc28408 Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana05_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana06_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana06_MD_2023.pdf new file mode 100644 index 0000000..8ac82f8 Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana06_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana07_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana07_MD_2023.pdf new file mode 100644 index 0000000..d98bb68 Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana07_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana08_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana08_MD_2023.pdf new file mode 100644 index 0000000..8911c19 Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana08_MD_2023.pdf differ diff --git a/1ano/2semestre/md/fichas/folhas_semana/folha_semana10_MD_2023.pdf b/1ano/2semestre/md/fichas/folhas_semana/folha_semana10_MD_2023.pdf new file mode 100644 index 0000000..8fe526e Binary files /dev/null and b/1ano/2semestre/md/fichas/folhas_semana/folha_semana10_MD_2023.pdf differ diff --git a/1ano/2semestre/md/slides/cap1_logica_primeira_ordem_MD_2022_23.pdf b/1ano/2semestre/md/slides/cap1_logica_primeira_ordem_MD_2022_23.pdf index 64967f6..4cabd77 100644 Binary files a/1ano/2semestre/md/slides/cap1_logica_primeira_ordem_MD_2022_23.pdf and b/1ano/2semestre/md/slides/cap1_logica_primeira_ordem_MD_2022_23.pdf differ diff --git a/1ano/2semestre/md/slides/cap2_enum_combinatoria_MD_2022_23.pdf b/1ano/2semestre/md/slides/cap2_enum_combinatoria_MD_2022_23.pdf new file mode 100644 index 0000000..81439de Binary files /dev/null and b/1ano/2semestre/md/slides/cap2_enum_combinatoria_MD_2022_23.pdf differ diff --git a/1ano/2semestre/md/slides/cap3_agrup_identidadescomb_MD_2022_23.pdf b/1ano/2semestre/md/slides/cap3_agrup_identidadescomb_MD_2022_23.pdf new file mode 100644 index 0000000..43a61f3 Binary files /dev/null and b/1ano/2semestre/md/slides/cap3_agrup_identidadescomb_MD_2022_23.pdf differ diff --git a/1ano/2semestre/md/slides/cap4_A_recorrencia_funcoes_geradoras_MD_2022_23.pdf b/1ano/2semestre/md/slides/cap4_A_recorrencia_funcoes_geradoras_MD_2022_23.pdf new file mode 100644 index 0000000..cddbb10 Binary files /dev/null and b/1ano/2semestre/md/slides/cap4_A_recorrencia_funcoes_geradoras_MD_2022_23.pdf differ diff --git a/1ano/2semestre/md/slides/cap4_B_recorrencia_funcoes_geradoras_MD_2022_23.pdf b/1ano/2semestre/md/slides/cap4_B_recorrencia_funcoes_geradoras_MD_2022_23.pdf new file mode 100644 index 0000000..706fd82 Binary files /dev/null and b/1ano/2semestre/md/slides/cap4_B_recorrencia_funcoes_geradoras_MD_2022_23.pdf differ diff --git a/1ano/2semestre/poo/guides/POO-2022-aula12.pdf b/1ano/2semestre/poo/guides/POO-2022-aula12.pdf new file mode 100644 index 0000000..d99e389 Binary files /dev/null and b/1ano/2semestre/poo/guides/POO-2022-aula12.pdf differ diff --git a/1ano/2semestre/poo/slides/POO_10_Lambda.pdf b/1ano/2semestre/poo/slides/POO_10_Lambda.pdf new file mode 100644 index 0000000..d2bfd6c Binary files /dev/null and b/1ano/2semestre/poo/slides/POO_10_Lambda.pdf differ diff --git a/1ano/2semestre/poo/src/aula02/AverageSpeed.java b/1ano/2semestre/poo/src/aula02/AverageSpeed.java index 6f1b11d..1605d14 100644 --- a/1ano/2semestre/poo/src/aula02/AverageSpeed.java +++ b/1ano/2semestre/poo/src/aula02/AverageSpeed.java @@ -1,11 +1,9 @@ package aula02; -import java.util.Scanner; - -// Código da package utils disponível em -// https://github.com/TiagoRG/uaveiro-leci/tree/master/1ano/2semestre/poo/src/utils import utils.UserInput; +import java.util.Scanner; + // Solução do exercício 5 public class AverageSpeed { diff --git a/1ano/2semestre/poo/src/aula03/Calendar.java b/1ano/2semestre/poo/src/aula03/Calendar.java index f1770ca..5e034cd 100644 --- a/1ano/2semestre/poo/src/aula03/Calendar.java +++ b/1ano/2semestre/poo/src/aula03/Calendar.java @@ -1,6 +1,7 @@ package aula03; import utils.UserInput; + import java.util.Scanner; // Solução do exercício 5 diff --git a/1ano/2semestre/poo/src/aula03/Grades.java b/1ano/2semestre/poo/src/aula03/Grades.java index c3426a4..493ab79 100644 --- a/1ano/2semestre/poo/src/aula03/Grades.java +++ b/1ano/2semestre/poo/src/aula03/Grades.java @@ -1,8 +1,9 @@ package aula03; -import java.util.Scanner; import utils.UserInput; +import java.util.Scanner; + // Solução do exercício 4 com o utilizador a introduzir as notas individualmente public class Grades { diff --git a/1ano/2semestre/poo/src/aula03/HiLo.java b/1ano/2semestre/poo/src/aula03/HiLo.java index b95fbb5..46d55b8 100644 --- a/1ano/2semestre/poo/src/aula03/HiLo.java +++ b/1ano/2semestre/poo/src/aula03/HiLo.java @@ -1,6 +1,7 @@ package aula03; import utils.UserInput; + import java.util.Random; import java.util.Scanner; diff --git a/1ano/2semestre/poo/src/aula03/Investment.java b/1ano/2semestre/poo/src/aula03/Investment.java index 92cb2cd..e3108aa 100644 --- a/1ano/2semestre/poo/src/aula03/Investment.java +++ b/1ano/2semestre/poo/src/aula03/Investment.java @@ -1,6 +1,7 @@ package aula03; import utils.UserInput; + import java.util.Scanner; // Solução do exercício 2 diff --git a/1ano/2semestre/poo/src/aula03/PrimesSum.java b/1ano/2semestre/poo/src/aula03/PrimesSum.java index b93a897..5784f25 100644 --- a/1ano/2semestre/poo/src/aula03/PrimesSum.java +++ b/1ano/2semestre/poo/src/aula03/PrimesSum.java @@ -2,6 +2,7 @@ package aula03; import utils.MathTools; import utils.UserInput; + import java.util.Scanner; // Solução do exercício 1 diff --git a/1ano/2semestre/poo/src/aula03/StringExtras.java b/1ano/2semestre/poo/src/aula03/StringExtras.java index d5db692..dcf6908 100644 --- a/1ano/2semestre/poo/src/aula03/StringExtras.java +++ b/1ano/2semestre/poo/src/aula03/StringExtras.java @@ -1,8 +1,9 @@ package aula03; -import java.util.Scanner; import utils.StringMethods; +import java.util.Scanner; + public class StringExtras { public static void main(String[] args) { Scanner sin = new Scanner(System.in); diff --git a/1ano/2semestre/poo/src/aula06/ex1/PersonTest.java b/1ano/2semestre/poo/src/aula06/ex1/PersonTest.java index f67c561..64362c4 100644 --- a/1ano/2semestre/poo/src/aula06/ex1/PersonTest.java +++ b/1ano/2semestre/poo/src/aula06/ex1/PersonTest.java @@ -1,8 +1,9 @@ package aula06.ex1; -import java.util.Scanner; import utils.DateYMD; +import java.util.Scanner; + public class PersonTest { public static void main(String[] args) { Scanner sin = new Scanner(System.in); diff --git a/1ano/2semestre/poo/src/aula06/ex1/Student.java b/1ano/2semestre/poo/src/aula06/ex1/Student.java index 31c0d95..b759397 100644 --- a/1ano/2semestre/poo/src/aula06/ex1/Student.java +++ b/1ano/2semestre/poo/src/aula06/ex1/Student.java @@ -1,6 +1,7 @@ package aula06.ex1; import utils.DateYMD; + import java.time.LocalDate; public class Student extends Person { diff --git a/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java index 6271af8..7724aa0 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java @@ -1,8 +1,8 @@ package aula08.ex1.Vehicles; import aula08.ex1.Interfaces.IKmTravelled; -import aula08.ex1.VehicleComp; import aula08.ex1.Main; +import aula08.ex1.VehicleComp; import utils.Validations; import java.util.Objects; diff --git a/1ano/2semestre/poo/src/aula08/ex2/Dishes/Dish.java b/1ano/2semestre/poo/src/aula08/ex2/Dishes/Dish.java index 327f113..30504aa 100644 --- a/1ano/2semestre/poo/src/aula08/ex2/Dishes/Dish.java +++ b/1ano/2semestre/poo/src/aula08/ex2/Dishes/Dish.java @@ -1,6 +1,7 @@ package aula08.ex2.Dishes; import aula08.ex2.Aliments.Aliment; + import java.util.LinkedList; import java.util.Objects; diff --git a/1ano/2semestre/poo/src/aula08/ex2/Menu.java b/1ano/2semestre/poo/src/aula08/ex2/Menu.java index 1af5082..724c53a 100644 --- a/1ano/2semestre/poo/src/aula08/ex2/Menu.java +++ b/1ano/2semestre/poo/src/aula08/ex2/Menu.java @@ -1,8 +1,13 @@ package aula08.ex2; import aula08.ex2.Aliments.*; -import aula08.ex2.Dishes.*; -import aula08.ex2.Enums.*; +import aula08.ex2.Dishes.DietDish; +import aula08.ex2.Dishes.Dish; +import aula08.ex2.Dishes.VeganDish; +import aula08.ex2.Enums.AlimentType; +import aula08.ex2.Enums.DishType; +import aula08.ex2.Enums.FishState; +import aula08.ex2.Enums.MeatType; import utils.Enums.Weekday; import java.util.LinkedHashMap; diff --git a/1ano/2semestre/poo/src/aula08/ex3/Purchase.java b/1ano/2semestre/poo/src/aula08/ex3/Purchase.java index d6a1afb..35622f9 100644 --- a/1ano/2semestre/poo/src/aula08/ex3/Purchase.java +++ b/1ano/2semestre/poo/src/aula08/ex3/Purchase.java @@ -1,6 +1,7 @@ package aula08.ex3; import aula08.ex3.Interfaces.IPurchase; + import java.util.LinkedHashMap; public class Purchase implements IPurchase { diff --git a/1ano/2semestre/poo/src/aula09/ex3/PlaneManager.java b/1ano/2semestre/poo/src/aula09/ex3/PlaneManager.java index 10a6d1c..7917322 100644 --- a/1ano/2semestre/poo/src/aula09/ex3/PlaneManager.java +++ b/1ano/2semestre/poo/src/aula09/ex3/PlaneManager.java @@ -1,6 +1,6 @@ package aula09.ex3; -import java.util.*; +import java.util.LinkedList; public class PlaneManager { private final LinkedList planes = new LinkedList<>(); diff --git a/1ano/2semestre/poo/src/aula11/ex1/WordPairCounter.java b/1ano/2semestre/poo/src/aula11/ex1/WordPairCounter.java index 1eee2b6..ccf4516 100644 --- a/1ano/2semestre/poo/src/aula11/ex1/WordPairCounter.java +++ b/1ano/2semestre/poo/src/aula11/ex1/WordPairCounter.java @@ -1,27 +1,17 @@ package aula11.ex1; -import java.io.*; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Scanner; +import java.util.TreeMap; public class WordPairCounter { public static void main(String[] args) { - TreeMap> wordPairs = new TreeMap<>() { - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (String word1 : this.keySet()) { - sb.append(word1).append("={"); - for (String word2 : this.get(word1).keySet()) { - sb.append(word2).append("=").append(this.get(word1).get(word2)).append(", "); - } - sb.delete(sb.length()-2, sb.length()).append("}\n"); - } - return sb.toString(); - } - }; + TreeMap> wordPairs = new TreeMap<>(); String text = ""; Path path = Paths.get((new Scanner(System.in)).nextLine()); @@ -42,6 +32,6 @@ public class WordPairCounter { word1Pair.put(word2, word1Pair.getOrDefault(word2, 0) + 1); } - System.out.println(wordPairs); + wordPairs.entrySet().forEach(System.out::println); } } diff --git a/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java b/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java index 00867ed..79cc9f7 100644 --- a/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java +++ b/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java @@ -1,15 +1,15 @@ package aula11.ex2; -import utils.MathTools; - -import java.io.*; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.Arrays; +import java.util.LinkedList; -public class Gradebook implements IGradeCalculator { +public class Gradebook { private final LinkedList students = new LinkedList<>(); + private final IGradeCalculator gradeCalculator = new SimpleGradeCalculator(); public void load(String filename) { LinkedList lines = new LinkedList<>(); @@ -42,16 +42,11 @@ public class Gradebook implements IGradeCalculator { } public double calculateAverageGrade(String name) { - return calculate(getStudent(name).getGrades()); - } - - @Override - public double calculate(LinkedList grades) { - return MathTools.media(grades); + return gradeCalculator.calculate(getStudent(name).getGrades()); } public void printAllStudents() { for (Student student : students) - System.out.printf("Nome: %s%nNota Final: %.2f%n%n", student.getName(), calculate(student.getGrades())); + System.out.printf("Nome: %s%nNota Final: %.2f%n%n", student.getName(), gradeCalculator.calculate(student.getGrades())); } } diff --git a/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java b/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java new file mode 100644 index 0000000..7192ed8 --- /dev/null +++ b/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java @@ -0,0 +1,13 @@ +package aula11.ex2; + +import java.util.LinkedList; + +public class SimpleGradeCalculator implements IGradeCalculator { + @Override + public double calculate(LinkedList grades) { + double sum = 0; + for (double n : grades) + sum += n; + return sum / grades.size(); + } +} 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); } } } diff --git a/1ano/2semestre/poo/src/aula11/ex4/FlightManager.java b/1ano/2semestre/poo/src/aula11/ex4/FlightManager.java index 9496d81..327c527 100644 --- a/1ano/2semestre/poo/src/aula11/ex4/FlightManager.java +++ b/1ano/2semestre/poo/src/aula11/ex4/FlightManager.java @@ -1,9 +1,11 @@ package aula11.ex4; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; -import java.io.*; import java.util.stream.Collectors; public class FlightManager { diff --git a/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java b/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java new file mode 100644 index 0000000..ed4681e --- /dev/null +++ b/1ano/2semestre/poo/src/aula12/ex1/DifferentWordCounter.java @@ -0,0 +1,22 @@ +package aula12.ex1; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Scanner; + +public class DifferentWordCounter { + public static void main(String[] args) throws FileNotFoundException { + Scanner reader = new Scanner(new FileReader((new Scanner(System.in)).nextLine())); + List words = new ArrayList<>(); + + while (reader.hasNext()) words.add(reader.next()); + + HashSet differentWords = new HashSet<>(words); + + System.out.println("Number of words: " + words.size()); + System.out.println("Number of different words: " + differentWords.size()); + } +} diff --git a/1ano/2semestre/poo/src/aula12/ex2/WordCounterByInitial.java b/1ano/2semestre/poo/src/aula12/ex2/WordCounterByInitial.java new file mode 100644 index 0000000..112b8ab --- /dev/null +++ b/1ano/2semestre/poo/src/aula12/ex2/WordCounterByInitial.java @@ -0,0 +1,39 @@ +package aula12.ex2; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.Scanner; +import java.util.TreeMap; + +public class WordCounterByInitial { + public static void main(String[] args) throws IOException { + TreeMap> words = new TreeMap<>() { + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Character initial : this.keySet()) { + sb.append(initial).append(": "); + for (String word : this.get(initial).keySet()) + sb.append(word).append(", ").append(this.get(initial).get(word)).append("; "); + sb.append("\b\n"); + } + return sb.toString(); + } + }; + + Arrays.stream(Files.readString(Path.of((new Scanner(System.in)).nextLine())) + .split("[\\s.,:'‘’;?!\\-*{}=+&/()\\[\\]”“\"]+")) + .filter(word -> word.length() > 2) + .map(String::toLowerCase) + .forEach(word -> { + char initial = word.charAt(0); + words.putIfAbsent(initial, new TreeMap<>()); + TreeMap initialWords = words.get(initial); + initialWords.put(word, initialWords.getOrDefault(word, 0) + 1); + }); + + System.out.println(words); + } +} diff --git a/1ano/2semestre/poo/src/aula12/ex3/Main.java b/1ano/2semestre/poo/src/aula12/ex3/Main.java new file mode 100644 index 0000000..3d473d2 --- /dev/null +++ b/1ano/2semestre/poo/src/aula12/ex3/Main.java @@ -0,0 +1,54 @@ +package aula12.ex3; + +import utils.UserInput; + +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; + +public class Main { + public static void main(String[] args) throws IOException { + List movies = new ArrayList<>(); + TreeSet titles = new TreeSet<>(); + + List unsortedMovies = new ArrayList<>(); + Scanner reader = new Scanner(new FileReader("datafiles/aula12/movies.txt")); + reader.nextLine(); + while (reader.hasNextLine()) { + String[] line = reader.nextLine().split("\t"); + Movie movie = new Movie(line[0], Double.parseDouble(line[1]), line[2], line[3], Integer.parseInt(line[4])); + unsortedMovies.add(movie); + titles.add(movie.title().toLowerCase()); + } + + + for (String title : titles) + movies.add(unsortedMovies.stream().filter(movie -> movie.title().equalsIgnoreCase(title)).findFirst().get()); + + System.out.println(movies); + System.out.println("\n\n\n"); + + System.out.println(movies.stream().sorted(Comparator.comparing(Movie::score).reversed()).toList()); + System.out.println("\n\n\n"); + + System.out.println(movies.stream().sorted(Comparator.comparing(Movie::duration)).toList()); + System.out.println("\n\n\n"); + + TreeMap genres = new TreeMap<>(); + movies.forEach(movie -> genres.put(movie.genre(), genres.getOrDefault(movie.genre(), 0) + 1)); + + System.out.println(genres); + System.out.println("\n\n\n"); + + String genre = UserInput.input(new Scanner(System.in), "Genre: "); + movies.stream().filter(movie -> movie.genre().equalsIgnoreCase(genre) && movie.score() > 60).forEach(movie -> { + try { + Files.writeString(Path.of("datafiles/aula12/myselection.txt"), movie.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } +} diff --git a/1ano/2semestre/poo/src/aula12/ex3/Movie.java b/1ano/2semestre/poo/src/aula12/ex3/Movie.java new file mode 100644 index 0000000..af68069 --- /dev/null +++ b/1ano/2semestre/poo/src/aula12/ex3/Movie.java @@ -0,0 +1,8 @@ +package aula12.ex3; + +public record Movie(String title, double score, String rating, String genre, int duration) { + @Override + public String toString() { + return String.format("%s\n\tScore: %.1f\n\tRating: %s\n\tGenre: %s\n\tDuration: %d\n\n", title, score, rating, genre, duration); + } +}