Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; //Used in Driver file
- //Movie lass file
- public class Movie{
- private int id;
- private String name;
- private String genre;
- private int duration;
- private String ageRating;
- private String description;
- public Movie(){
- id = 0;
- name = "NULL";
- genre = "NULL";
- duration = 0;
- ageRating = "NULL";
- description = "NULL";
- }
- public Movie(int idNo, String na, String gen, int dur, String ageR, String desc){
- id = idNo;
- name = na;
- genre = gen;
- duration = dur;
- ageRating = ageR;
- description = desc;
- }
- public void setId(int idNo){
- id = idNo;
- }
- public void setName(String na){
- name = na;
- }
- public void setGenre(String gen){
- genre = gen;
- }
- public String getGenre(){
- return genre;
- }
- public void setDuration(int dur){
- duration = dur;
- }
- public void setAgeRating(String ageR){
- ageRating = ageR;
- }
- public String getAgeRating(){
- return ageRating;
- }
- public void setDescription(String desc){
- description = desc;
- }
- public void displayRow(){
- System.out.printf("%-1s %-3s %-50s %-23s %-8s %-1s %n", "|", id, name, genre, ageRating, "|");
- }
- public void displayDetails(){
- System.out.println("Movie Id : " + id);
- System.out.println("Movie Name : " + name);
- System.out.println("Genre : " + genre);
- System.out.println("Duration : " + duration);
- System.out.println("Age Rating : " + ageRating);
- System.out.println("Description : \n" + description);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////
- //In Functions File
- //Global Variable
- public static int size = 5; //Size of array/maximum number of movies that can be recorded
- public static Movie movies[] = new Movie[size]; //array of Movie class object
- public static int index = 0; //index of movie
- public static Scanner input = new Scanner(System.in);
- public static String pause; //system("Pause") / getch() dummy (OR variable used to pause wait and for user to enter)
- //Initialist array of objects
- public static void initialiseArray(){
- for(int i = 0; i<size; i++){
- movies[i] = new Movie();
- }
- }
- //Call main method
- static void mainCaller(){
- main(null);
- }
- //Clear Command Line Console
- public static void clearScreen(){
- System.out.print("\033[H\033[2J");
- System.out.flush();
- }
- //Main Menu : View
- public static void View(){
- char choice;
- System.out.println("❖--------------------◂View▸--------------------❖");
- System.out.println(" 1. View all.....................(Table Format)");
- System.out.println(" 2. List all by Genre............(Table Format)");
- System.out.println(" 3. List all by Age Rating.......(Table Format)");
- System.out.println(" 4. Search by Name............(Detailed Format)");
- System.out.println(" 5. Go Back......................(To Main Menu)");
- System.out.println("*--------------------<****>--------------------*\n");
- System.out.print("Please enter your choice : ");
- choice = input.next().charAt(0);
- clearScreen();
- switch(choice){
- //View All
- case '1':
- //Title
- System.out.printf("%49s %n","View All");
- //Table Border
- System.out.print("◤");
- for(int i = 0; i<89; i++){
- System.out.print("=");
- }
- System.out.println("◥");
- //Table Header
- System.out.printf("%-1s %-3s %-50s %-20s %-11s %-1s %n", "|", "ID", "Name", "Genre","Age Rating", "|");
- //Table Divider
- System.out.print("|");
- for(int i = 0; i<89; i++){
- System.out.print("=");
- }
- System.out.println("|");
- //Display each row of recorded movies
- for(int i = 0; i<size; i++){
- movies[i].displayRow();
- }
- //Table Border
- System.out.print("◣");
- for(int i = 0; i<89; i++){
- System.out.print("=");
- }
- System.out.println("◢");
- //Pause screen before clearing
- System.out.print("\nPress enter to continue...");
- pause = input.nextLine();
- pause = input.nextLine();
- clearScreen();
- mainCaller();
- //List all by Genre
- case '2':
- String genre;
- boolean valid = true;
- do{
- System.out.println("*-------------------<Genres>-------------------*");
- System.out.println(" 1. Action 2. Adventure");
- System.out.println(" 3. Comedy 4. Drama");
- System.out.println(" 5. Horror 6. Sci-Fi");
- System.out.println(" 7. Romance 8. Others");
- System.out.println(" 9. Go Back.....................(To View Menu)");
- System.out.println("*-------------------<******>-------------------*\n");
- if(!valid){
- System.out.print("'" + choice + "' is an invalid choice.\n\n");
- }
- valid = true;
- System.out.print("Please enter your choice : ");
- choice = input.next().charAt(0);
- switch(choice){
- case '1':
- genre = "Action";
- break;
- case '2':
- genre = "Adventure";
- break;
- case '3':
- genre = "Comedy";
- break;
- case '4':
- genre = "Drama";
- break;
- case '5':
- genre = "Horror";
- break;
- case '6':
- genre = "Sci-Fi";
- break;
- case '7':
- genre = "Romance";
- break;
- case '8':
- genre = "Others";
- break;
- case '9':
- clearScreen();
- View();
- default:
- clearScreen();
- valid = false;
- }
- }while(!valid);
- break;
- //List all by Age Rating
- case '3':
- break;
- //Search by Name
- case '4':
- break;
- //Go Back to Main Menu
- case '5':
- mainCaller();
- default:
- System.out.println("'" + choice + "' is an invalid choice.");
- View();
- }
- }
- //List all by Genre
- void givenGenre(String genre, int high){
- if (high < 0){
- return;
- }
- else if (genre == movies[high].getGenre() ){
- movies[high].displayRow();
- givenGenre(genre, high-1);
- }
- else {
- givenGenre(genre, high-1);
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////
- public static void main(String[] args){
- //Create input object of Scanner class
- String dummyS;
- int dummyI;
- //Initialise array of objects of Movie class
- if(index == 0){
- initialiseArray();
- }
- movies[index].setId(index+1);
- System.out.println("Enter Movie Name : ");
- dummyS = input.nextLine();
- movies[index].setName(dummyS);
- if(index == 4){
- View();
- }
- if(index<4){
- index++;
- //call mainCaller to call main method
- mainCaller();
- }
- }
- }
Add Comment
Please, Sign In to add comment