Question: Movie Rating system Java and MySQL: The description for this assignment is below: The Movie Rating System (MRS) is in-console and has two main components
Movie Rating system Java and MySQL:
The description for this assignment is below:
The Movie Rating System (MRS) is in-console and has two main components a) the movie catalog management component; b) movie catalog viewing and rating component. The movie catalog management component should avail an admin user with the following functionalities: ability to view, add, update, and delete movies from the catalog. As part of the update admin should not have the ability to update any of the rating related information of a movie. Update should allow other attributes such as the movie description, title. The movie catalog viewing and rating component allows any user to search and view movies and add a rating and a comment to a movie.
Implementation Details
Command line Menu:
Main Menu:
Admin
User
Exit
User could select an option from this list. If user select 1, it should display Admin Menu with the following options:
Admin Menu:
Add new movie
Search and update movie
Search and delete
Implements these options for admin personnel.
In main menu, if user select 2 from the Main Menu it should display user menu. User menu should contains the following options:
User Menu:
Search movie
Rate movie
Add comments
Implement these options for user activities.
The code below is what I have thus far. I am really stumped with how to proceed with this. Any help would be greatly appreciated.
package finalProject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
private String movieID;
private String movie_title;
private String score;
private String count;
private String description;
private String commentID;
private String comment;
private String ratingID;
private String rating;
public static void main(String[] args) throws SQLException{
boolean exit = false;
int selection = 0;
Connection connection;
Statement stmt;
ResultSet rs;
PreparedStatement preparedStatement;
Scanner input = new Scanner(System.in);
connection = getConnection();
loadDriver();
//Loop until until selects 'exit'
do {
//loop until user enter a valid input
do {
//catches invalid type input
try {
//print main menu
System.out.println("Main Menu");
System.out.println("1) Admin");
System.out.println("2) User");
System.out.println("3) Exit");
selection = input.nextInt();
}catch(InputMismatchException e) {
System.out.println("Error: " + e.getMessage());
input.next();
}
//Loop while selection is less than 1 or greater than 3
}while(selection<1 || selection> 3);
//switch on selection
switch(selection) {
case 1:
//Loop until user inputs valid input
do {
//catches invalid input types
try {
//Present selection 1: Admin menu
System.out.println("Admin Menu");
System.out.println("1) Add new movie ");
System.out.println("2) Search and update movie");
System.out.println("3) Search and delete ");
//Exit back to main menu
System.out.println("4) Exit ");
selection = input.nextInt();
}catch(InputMismatchException e) {
System.out.println("Error: " + e.getMessage());
input.next();
}
}while(selection<1 || selection> 3);
switch(selection) {
//Could have option to display comments for bonus points
//Add new movie
case 1:
//bonus points for displaying all comments
//mysql insert statement
//insertToMovieTable(connection);
//break out of statement
System.out.print("Enter movie name: ");
String title = input.nextLine();
System.out.print("Enter movie description: ");
String description = input.nextLine();
Double score = input.nextDouble();
//if movie name matches name or description
try {
//These ??? are values unknown at this point
PreparedStatement insert = connection.prepareStatement("insert into movie values (? , ? , ?) ");
//Takes care of index value
int i=1;
//replaces ? in above statement. Insert .setString is used because is text value
insert.setString(i++, title);//if an int would need setInt
insert.setDouble(i++, score);
insert.setString(i++, description);
insert.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
break;
//Search and update movie
case 2:
//break out of statement
break;
//Search and delete
case 3:
//break out of statement
break;
}
//break out of switch statement
break;
case 2:
//Loop until user inputs valid input
do {
//catches invalid input types
try {
//Present selection 1: Admin menu
System.out.println("User Menu");
System.out.println("1) Search movie ");
System.out.println("2) Rate movie ");
System.out.println("3) Add comments ");
selection = input.nextInt();
}catch(InputMismatchException e) {
System.out.println("Error: " + e.getMessage());
input.next();
}
}while(selection<1 || selection> 3);
switch(selection) {
//Option 1: Search movie
case 1:
//break out of statement
break;
//Option 2: Rate movies
case 2:
//break out of statement
break;
//Option 3: Add comments
case 3:
//break out of statement
break;
}
//break out of switch statement
break;
//exit
case 3:
try {
System.out.println("Are you sure you want to exit? (1 for yes)");
int answer = input.nextInt();
if (answer == 1) {
// set variable to break out of loop
exit = true;
} else
continue;
}catch(InputMismatchException e) {
System.out.println("Error: " + e.getMessage());
}
// break out of switch statement
break;
}
}while(!exit);
}
private static Connection getConnection() {
Connection connection = null;
try {
connection = DriverManager
.getConnection("jdbc:mysql://localhost/movieDatabase?" + "user=root&password=test123");
System.out.println("Database connection acquired");
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
return connection;
}
private static void loadDriver() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Driver Loaded");
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static void insertToMoviesTable(Connection connection) throws SQLException {
PreparedStatement prepareStatement = connection.prepareStatement(" INSERT INTO MOVIE " +
" VALUES " +
" ('Hello', 1, 1,'horror') ");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
