This commit is contained in:
2026-05-09 03:50:38 +03:30
parent 7ffa76fd45
commit 0aa0a60e74
5 changed files with 70 additions and 39 deletions
+24 -19
View File
@@ -7,41 +7,46 @@ import java.io.IOException;
import java.util.*;
public class Parser {
static List<Movie> movies = new ArrayList<>();
private List<Movie> movies = new ArrayList<>();
public Parser(String filePath) throws IOException {
setUp(filePath);
}
public List<Movie> sortByTitle() {
List<Movie> sortedByTitle = new ArrayList<>(movies);
// Sort movies alphabetically by title
//TODO
// TODO: Sort the 'sortedByTitle' list alphabetically by the movie's title.
// Hint: You can use Collections.sort() or the List.sort() method along with a custom Comparator.
// Example: Comparator.comparing(Movie::getTitle)
return sortedByTitle;
}
public List<Movie> sortByRating() {
List<Movie> sortedByRating = new ArrayList<>(movies);
// Sort movies by rating (highest to lowest)
//TODO
// TODO: Sort the 'sortedByRating' list by the movie's rating in descending order (highest to lowest).
// Hint: Use Double.compare() in your Comparator or Comparator.comparingDouble().reversed().
return sortedByRating;
}
public List<Movie> sortByYear() {
List<Movie> sortedByYear = new ArrayList<>(movies);
// Sort movies by year (newest to oldest)
//TODO
// TODO: Sort the 'sortedByYear' list by the movie's release year in descending order (newest to oldest).
// Hint: Compare the year integers. Use Integer.compare() or Comparator.comparingInt().reversed().
return sortedByYear;
}
public void setUp() throws IOException {
// Parse the HTML file using Jsoup
//TODO
private void setUp(String filePath) throws IOException {
// TODO: Create a java.io.File object using the given 'filePath'.
// TODO: Parse the HTML file using Jsoup.parse(file, "UTF-8"). This returns a Document object.
// Extract data from the HTML
//TODO
// TODO: Extract the list of movie elements from the Document.
// Hint: Use document.select() or document.getElementsByClass() to find all elements with the class "movie".
// Iterate through each movie div to extract movie data
//TODO
// TODO: Iterate through each movie Element.
// For each movie element:
// 1. Find the title element (e.g., using selector "h3.movie-title") and get its text.
// 2. Find the rating element (e.g., using selector "span.movie-rating"). Extract the text, remove the "/10" part, and parse it to a double.
// 3. Find the year element (e.g., using selector "span.movie-year"). Extract the text and parse it to an int.
// 4. Create a new Movie object with these values and add it to the 'movies' list.
}
public static void main(String[] args) {
// You can test your code here before you run the unit tests
}
}
}