diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e292cb0..74f3538 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,5 @@ import java.io.IOException; +import java.util.List; public class Main { public static void main(String[] args) { @@ -9,11 +10,25 @@ public class Main { // Instantiate the parser Parser parser = new Parser(filePath); - // TODO: You can test your code here before you run the unit tests. - // Example: Call your sorting methods, iterate through the returned list, - // and print out the movies to see if they match the expected results in the Help folder. + System.out.println("====== Sorted by title ======"); + List sortedByTitle = parser.sortByTitle(); + for (int i = 1; i <= sortedByTitle.size(); i++) { + System.out.println(i + ". " + sortedByTitle.get(i - 1)); + } + + System.out.println("\n====== Sorted by rating ======"); + List sortedByRating = parser.sortByRating(); + for (int i = 1; i <= sortedByRating.size(); i++) { + System.out.println(i + ". " + sortedByRating.get(i - 1)); + } + + System.out.println("\n====== Sorted by year ======"); + List sortedByYear = parser.sortByYear(); + for (int i = 1; i <= sortedByYear.size(); i++) { + System.out.println(i + ". " + sortedByYear.get(i - 1)); + } - System.out.println("Movies parsed successfully! Total movies: " + parser.sortByTitle().size()); + System.out.println("\nMovies parsed successfully! Total movies: " + parser.sortByTitle().size()); } catch (IOException e) { System.err.println("Error reading or parsing the HTML file: " + e.getMessage()); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java index d74bbb8..2ad5555 100644 --- a/src/main/java/Parser.java +++ b/src/main/java/Parser.java @@ -35,15 +35,15 @@ public class Parser { File file = new File(filePath); Document doc = Jsoup.parse(file, "UTF-8"); - Elements movieElements = doc.select("movie"); + Elements movieElements = doc.select("div.movie"); for (Element movieElement : movieElements) { - String title = movieElement.select("h3.movie-title").toString(); + String title = movieElement.select("h3.movie-title").text(); - Double rating = Double.parseDouble(movieElement.select("span.movie-rating").toString().replace("/10","")); + Double rating = Double.parseDouble(movieElement.select("span.movie-rating").text().replace("/10","")); - int year = Integer.parseInt(movieElement.select("span.movie-year").toString()); + int year = Integer.parseInt(movieElement.select("span.movie-year").text()); Movie movie = new Movie(title, rating, year); movies.add(movie);