HW5
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import java.util.Objects;
|
||||
|
||||
public class Movie {
|
||||
private String title;
|
||||
private double rating;
|
||||
private int year;
|
||||
|
||||
public Movie(String title, double rating, int year) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public double getRating() {
|
||||
return rating;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
//TODO
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Movie movie = (Movie) o;
|
||||
return Double.compare(movie.rating, rating) == 0 && movie.year == year && Objects.equals(title, movie.title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class Parser {
|
||||
static List<Movie> movies = new ArrayList<>();
|
||||
|
||||
public List<Movie> sortByTitle() {
|
||||
List<Movie> sortedByTitle = new ArrayList<>(movies);
|
||||
// Sort movies alphabetically by title
|
||||
//TODO
|
||||
return sortedByTitle;
|
||||
}
|
||||
|
||||
public List<Movie> sortByRating() {
|
||||
List<Movie> sortedByRating = new ArrayList<>(movies);
|
||||
// Sort movies by rating (highest to lowest)
|
||||
//TODO
|
||||
return sortedByRating;
|
||||
}
|
||||
|
||||
public List<Movie> sortByYear() {
|
||||
List<Movie> sortedByYear = new ArrayList<>(movies);
|
||||
// Sort movies by year (newest to oldest)
|
||||
//TODO
|
||||
return sortedByYear;
|
||||
}
|
||||
|
||||
public void setUp() throws IOException {
|
||||
// Parse the HTML file using Jsoup
|
||||
//TODO
|
||||
|
||||
// Extract data from the HTML
|
||||
//TODO
|
||||
|
||||
// Iterate through each movie div to extract movie data
|
||||
//TODO
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// You can test your code here before you run the unit tests
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<div id="page">
|
||||
<section id="movies">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h1>Movie List: To Scrape</h1>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Godfather</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.2/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1972</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Shawshank Redemption</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.3/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1994</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Dark Knight</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.0/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">2008</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">12 Angry Men</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.0/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1957</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Schindler's List</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.0/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1993</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Lord of the Rings: The Return of the King</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">9.0/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">2003</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Pulp Fiction</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.9/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1994</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Lord of the Rings: The Fellowship of the Ring</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.8/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">2001</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Forrest Gump</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.8/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1994</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Fight Club</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.8/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1999</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Inception</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.8/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">2010</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Star Wars: Episode V - The Empire Strikes Back</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.7/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1980</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">The Matrix</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.7/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1999</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Goodfellas</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.7/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">1990</span><br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 movie">
|
||||
<h3 class="movie-title">Interstellar</h3>
|
||||
<div class="movie-info">
|
||||
<strong>Rating:</strong> <span class="movie-rating">8.6/10</span><br>
|
||||
<strong>Year:</strong> <span class="movie-year">2014</span><br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
Reference in New Issue
Block a user