Skip to content

Commit 0874bac

Browse files
committed
add exercise 8
1 parent 7cb5058 commit 0874bac

File tree

7 files changed

+1393
-0
lines changed

7 files changed

+1393
-0
lines changed

.idea/runConfigurations/Run_All_tests_in_Execise_8.xml

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/kotlin/exercise8/MovieDB.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package exercise8
2+
3+
/**
4+
* Task: Write a MovieDB class that implements the MovieDBApi interface.
5+
*
6+
* Define a constructor of MovieDB class which accepts the list of movies as parameter.
7+
*
8+
* Implement methods defined by MovieDBApi.
9+
*
10+
*/
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package exercise8
2+
3+
import java.time.LocalDate
4+
5+
/**
6+
* Represents a movie director.
7+
*
8+
* @property name The name of the movie director.
9+
*/
10+
data class MovieDirector(val name: String)
11+
12+
/**
13+
* Represents a movie actor.
14+
*
15+
* @property name The name of the actor.
16+
*/
17+
data class MovieActor(val name: String)
18+
19+
/**
20+
* Represents a Movie.
21+
*
22+
* @property title The title of the movie.
23+
* @property budget The budget of the movie in dollars.
24+
* @property revenue The revenue of the movie in dollars.
25+
* @property releaseDate The release date of the movie.
26+
* @property runtimeInMinutes The runtime of the movie in minutes.
27+
* @property director The director of the movie.
28+
* @property genres The genres of the movie.
29+
* @property actors The actors in the movie.
30+
* @property rating The rating of the movie.
31+
*/
32+
data class Movie(
33+
val title: String,
34+
val budget: Long,
35+
val revenue: Long,
36+
val releaseDate: LocalDate,
37+
val runtimeInMinutes: Int,
38+
val director: MovieDirector,
39+
val genres: List<String>,
40+
val actors: List<MovieActor>,
41+
val rating: Double
42+
)
43+
44+
interface MovieDBApi {
45+
/**
46+
*
47+
* Retrieves a list of all movies that feature the given actor.
48+
*
49+
* @param actor The actor to search for.
50+
* @return A list of movies that feature the given actor.
51+
*/
52+
fun getAllMoviesByActor(actor: MovieActor): List<Movie>
53+
54+
/**
55+
* Retrieves a list of movies with the best profits.
56+
*
57+
* Movie profits are calculated by deducting revenue from its budget.
58+
*
59+
* @param numOfMovies The number of movies to retrieve.
60+
* @return A list of movies with the best earnings.
61+
*/
62+
fun getMoviesWithBiggestProfit(numOfMovies: Int): List<Movie>
63+
64+
/**
65+
* Retrieves the best-rated movie featuring the given actor.
66+
*
67+
* @param actor The actor to search for.
68+
* @return The best-rated movie featuring the given actor, or null if no movie is found.
69+
*/
70+
fun getBestRatedMovieByActor(actor: MovieActor): Movie?
71+
72+
/**
73+
* Retrieves a list of all movies released in the specified year.
74+
*
75+
* @param year The year of release.
76+
* @return A list of movies released in the specified year.
77+
*/
78+
fun getAllMoviesByYear(year: Int): List<Movie>
79+
80+
/**
81+
* Retrieves a list of all movies that belong to the given genre.
82+
*
83+
* @param genre The genre to search for.
84+
* @return A list of movies that belong to the given genre.
85+
*/
86+
fun getAllMoviesByGenre(genre: String): List<Movie>
87+
88+
/**
89+
* Retrieves a list of the best-rated movies.
90+
*
91+
* The best-rated movies are determined by their rating, with the highest-rated movies appearing first.
92+
*
93+
* @param numOfMovies The number of movies to retrieve.
94+
* @return A list of the best-rated movies.
95+
*/
96+
fun getBestRatedMovies(numOfMovies: Int): List<Movie>
97+
98+
/**
99+
* Retrieves the movie director who has directed the most movies.
100+
*
101+
* @return The movie director with the most movies directed.
102+
*/
103+
fun getDirectorWithMostMoviesDirected(): MovieDirector
104+
105+
/**
106+
* Retrieves a list of actor pairs who have the most movies they acted in together.
107+
*
108+
* @return A list of MovieActor objects representing the actors with the most costarred movies.
109+
*/
110+
fun getActorsWithMostCostarredMovies(): List<Pair<MovieActor, MovieActor>>
111+
}
112+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package exercise8
2+
3+
import common.FileReader
4+
5+
6+
private fun parseMovies(moviesLines: List<String>): List<Movie> {
7+
TODO("Implement parsing of the file content")
8+
}
9+
10+
fun main() {
11+
val moviesCSVFile = FileReader.readFileInResources("exercise8/movies.csv")
12+
val movies = parseMovies(moviesCSVFile)
13+
14+
val movieDBApi : MovieDBApi = TODO("Instantiate MovieDB")
15+
}

0 commit comments

Comments
 (0)