develop #1

Merged
MehrdadShirvani merged 3 commits from develop into main 2026-05-15 13:10:46 +00:00
2 changed files with 23 additions and 8 deletions
Showing only changes of commit a802256569 - Show all commits
+19 -4
View File
@@ -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<Movie> 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<Movie> 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<Movie> 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());
+4 -4
View File
@@ -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);