Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views3 pages

Movie

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Movie

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Class Diagram

To connect our project to a database, we create the following Singleton class:


The ConnexionBD class is a Singleton, and it simulates a connection to a database called
'JavaIsitcom':
public class ConnexionBD {
private static Connection connection;
private ConnexionBD() {
try {
connection =
DriverManager.getConnection("jdbc:mysql://localhost/JavaIsitcom",
"root", "");
System.out.println("Connexion établie...");
}
catch (SQLException e) {
System.out.println("Problème établissement connexion...");
e.printStackTrace();
}
}
public static Connection getConnection() {
if (connection == null) {
new ConnexionBD();
}
return connection;
}
}
You should directly use the ConnexionBD.getConnection() method in
the ’Theatre’ class to interact with the database for CRUD operations.

Figure 1 : ‘ForeignMovie’ Table Structure

Figure 2 : ‘Theatre’ Table Structure

Part 1: Implementation
1. Create the Movie Class
• Implement the ”Comparable” interface, to sort the movies by id.
3. Create the TunisianMovie Class (Subclass of Movie)

4. Create the ForeignMovie Class (Subclass of Movie)


5. Create a Custom checked Exception:
NotFoundMovieOrTheatreException
• Example usage: Throw this exception when a movie or a theatre is not found with
the specified ID.
6. Create the Theater Class
Notice: We are only interested in foreign movies.
• Additional methods:
• public static void addNewTheatreToDB(Theatre t):
Add a new theatre to the database table 'theatre’.

• public static void


assignForeignMovieToTheatre(int theatreId,
ForeignMovie fm): Assign a ForeignMovie ‘fm’ to a theatre
with the ID = ’theatreId’.
• Throw a ’NotFoundMovieOrTheatreException’ if
the theatre does not exist.

• public static List<Theatre> getAllTheatre():


Display all theatres.

• public static void deleteForeignMovie(int id):


Delete a movie by ID. If the movie does not exist.
• Throw a ’NotFoundMovieOrTheatreException’ if
the movie does not exist.

• public static List<ForeignMovie>


getAllForeignMoviesByTheatre(int idTheatre): Get
all foreign movies that exist in the theatre with ID idTheatre.
• Throw a ’NotFoundMovieOrTheatreException’ if
the movie or the theatre does not exist.

• public static List<ForeignMovie>


searchMoviesByDirectorName(String directorName,
int idTheatre): Search for movies directed by directorName
in the theatre with ID idTheatre.
• Throw a ’NotFoundMovieOrTheatreException’ if
the movie or the theatre does not exist.

• public static void toProjectMovie(String


movieTitle, int theatreId): Check if a movie with the
name 'movieTitle' is being projected in the theatre with ID =
theatreId.
• Throw a ’NotFoundMovieOrTheatreException’ if
the movie or the theatre does not exist.
• public static ArrayList sortById(int idTheatre):
Sort movies by ID (using the Comparable interface and the
compareTo method, which is already implemented in the 'Movie'
class).

• public static ArrayList sortByPrice(int


idTheatre) : Sort foreign movies by price (using the
Comparator interface implemented with a lambda expression).
Part 2: The Main Class
Test ‘all’ methods.

You might also like