tiffprag

Movie Full Code

Jan 21st, 2020
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.06 KB | None | 0 0
  1. import java.util.Scanner;   //Used in Driver file
  2.  
  3. //Movie lass file
  4. public class Movie{
  5.     private int id;
  6.     private String name;
  7.     private String genre;
  8.     private int duration;
  9.     private String ageRating;
  10.     private String description;
  11.  
  12.     public Movie(){
  13.         id = 0;
  14.         name = "NULL";
  15.         genre = "NULL";
  16.         duration = 0;
  17.         ageRating = "NULL";
  18.         description = "NULL";
  19.     }
  20.  
  21.     public Movie(int idNo, String na, String gen, int dur, String ageR, String desc){
  22.         id = idNo;
  23.         name = na;
  24.         genre = gen;
  25.         duration = dur;
  26.         ageRating = ageR;
  27.         description = desc;
  28.     }
  29.  
  30.     public void setId(int idNo){
  31.         id = idNo;
  32.     }
  33.  
  34.     public void setName(String na){
  35.         name = na;
  36.     }
  37.  
  38.     public void setGenre(String gen){
  39.         genre = gen;
  40.     }
  41.  
  42.     public String getGenre(){
  43.         return genre;
  44.     }
  45.  
  46.     public void setDuration(int dur){
  47.         duration = dur;
  48.     }
  49.  
  50.     public void setAgeRating(String ageR){
  51.         ageRating = ageR;
  52.     }
  53.  
  54.     public String getAgeRating(){
  55.         return ageRating;
  56.     }
  57.  
  58.     public void setDescription(String desc){
  59.         description = desc;
  60.     }
  61.  
  62.     public void displayRow(){
  63.         System.out.printf("%-1s %-3s %-50s %-23s %-8s %-1s %n", "|", id, name, genre, ageRating, "|");
  64.     }
  65.  
  66.     public void displayDetails(){
  67.         System.out.println("Movie Id : " + id);
  68.         System.out.println("Movie Name : " + name);
  69.         System.out.println("Genre : " + genre);
  70.         System.out.println("Duration : " + duration);
  71.         System.out.println("Age Rating : " + ageRating);
  72.         System.out.println("Description : \n" + description);
  73.     }
  74.  
  75. //////////////////////////////////////////////////////////////////////////////////////////////
  76. //////////////////////////////////////////////////////////////////////////////////////////////
  77.  
  78.     //In Functions File
  79.     //Global Variable
  80.     public static int size = 5; //Size of array/maximum number of movies that can be recorded
  81.  
  82.     public static Movie movies[] = new Movie[size]; //array of Movie class object
  83.  
  84.     public static int index = 0;    //index of movie
  85.  
  86.     public static Scanner input = new Scanner(System.in);
  87.  
  88.     public static String pause; //system("Pause") / getch() dummy (OR variable used to pause wait and for user to enter)
  89.  
  90.     //Initialist array of objects
  91.     public static void initialiseArray(){
  92.         for(int i = 0; i<size; i++){
  93.             movies[i] = new Movie();
  94.         }
  95.     }
  96.  
  97.     //Call main method
  98.     static void mainCaller(){
  99.         main(null);
  100.     }
  101.  
  102.     //Clear Command Line Console
  103.     public static void clearScreen(){  
  104.         System.out.print("\033[H\033[2J");  
  105.         System.out.flush();  
  106.     }
  107.  
  108.     public static final String ANSI_RESET = "\u001B[0m";
  109.     public static final String ANSI_GREEN = "\u001B[32m";
  110.  
  111.     //Main Menu : View
  112.     public static void View(){
  113.         char choice;
  114.         System.out.println(ANSI_GREEN + "❖--------------------◂View▸--------------------❖" + ANSI_RESET);
  115.         //System.out.println("❖--------------------◂View▸--------------------❖");
  116.         System.out.println(" 1. View all.....................(Table Format)");
  117.         System.out.println(" 2. List all by Genre............(Table Format)");
  118.         System.out.println(" 3. List all by Age Rating.......(Table Format)");
  119.         System.out.println(" 4. Search by Name............(Detailed Format)");
  120.         System.out.println(" 5. Go Back......................(To Main Menu)");
  121.         System.out.println("❖--------------------◂♦♦♦♦▸--------------------❖\n");
  122.  
  123.         System.out.print("Please enter your choice : ");
  124.         choice = input.next().charAt(0);
  125.  
  126.         clearScreen();
  127.  
  128.          switch(choice){
  129.             //View All
  130.             case '1':
  131.                 //Title
  132.                 System.out.printf("%49s %n","View All");
  133.  
  134.                 //Table Border
  135.                 System.out.print("◤");
  136.                 for(int i = 0; i<89; i++){
  137.                     System.out.print("=");
  138.                 }
  139.  
  140.                 System.out.println("◥");
  141.  
  142.                 //Table Header
  143.                 System.out.printf("%-1s %-3s %-50s %-20s %-11s %-1s %n", "|", "ID", "Name", "Genre","Age Rating", "|");
  144.                
  145.                 //Table Divider
  146.                 System.out.print("|");
  147.                 for(int i = 0; i<89; i++){
  148.                     System.out.print("=");
  149.                 }
  150.                 System.out.println("|");
  151.  
  152.                 //Display each row of recorded movies
  153.                 for(int i = 0; i<size; i++){
  154.                     movies[i].displayRow();
  155.                 }
  156.  
  157.                 //Table Border
  158.                 System.out.print("◣");
  159.  
  160.                 for(int i = 0; i<89; i++){
  161.                     System.out.print("=");
  162.                 }
  163.  
  164.                 System.out.println("◢");
  165.  
  166.                 //Pause screen before clearing
  167.                 System.out.print("\nPress enter to continue...");
  168.                 pause = input.nextLine();
  169.                 pause = input.nextLine();
  170.  
  171.                 clearScreen();
  172.  
  173.                 mainCaller();
  174.  
  175.             //List all by Genre
  176.             case '2':
  177.                 String genre;
  178.                 boolean valid = true;
  179.  
  180.                 do{
  181.                     System.out.println("❖-------------------◂Genres▸-------------------❖");
  182.                     System.out.println(" 1. Action          2. Adventure");
  183.                     System.out.println(" 3. Comedy          4. Drama");
  184.                     System.out.println(" 5. Horror          6. Sci-Fi");
  185.                     System.out.println(" 7. Romance         8. Others");
  186.                     System.out.println(" 9. Go Back.....................(To View Menu)");
  187.                     System.out.println("❖--------------------◂♦♦♦♦▸--------------------❖\n");
  188.  
  189.                     if(!valid){
  190.                         System.out.print("'" + choice + "' is an invalid choice.\n\n");
  191.                     }
  192.  
  193.                     valid = true;
  194.  
  195.                     System.out.print("Please enter your choice : ");
  196.                     choice = input.next().charAt(0);
  197.                     switch(choice){
  198.                         case '1':
  199.                             genre = "Action";
  200.                             break;
  201.  
  202.                         case '2':
  203.                             genre = "Adventure";
  204.                             break;
  205.  
  206.                         case '3':
  207.                             genre = "Comedy";
  208.                             break;
  209.  
  210.                         case '4':
  211.                             genre = "Drama";
  212.                             break;
  213.  
  214.                         case '5':
  215.                             genre = "Horror";
  216.                             break;
  217.  
  218.                         case '6':
  219.                             genre = "Sci-Fi";
  220.                             break;
  221.  
  222.                         case '7':
  223.                             genre = "Romance";
  224.                             break;
  225.  
  226.                         case '8':
  227.                             genre = "Others";
  228.                             break;
  229.  
  230.                         case '9':
  231.                             clearScreen();
  232.                             View();
  233.  
  234.                         default:
  235.                             clearScreen();
  236.                             valid = false;
  237.                     }
  238.                 }while(!valid);
  239.  
  240.                 break;
  241.  
  242.             //List all by Age Rating
  243.             case '3':
  244.  
  245.             break;
  246.  
  247.             //Search by Name
  248.             case '4':
  249.  
  250.             break;
  251.  
  252.             //Go Back to Main Menu
  253.             case '5':
  254.                 mainCaller();
  255.  
  256.             default:
  257.                 System.out.println("'" + choice + "' is an invalid choice.");
  258.                 View();
  259.          }
  260.  
  261.     }
  262.  
  263.     //List all by Genre
  264.     void givenGenre(String genre, int high){
  265.         if (high < 0){
  266.           return;
  267.         }
  268.         else if (genre == movies[high].getGenre() ){
  269.           movies[high].displayRow();
  270.           givenGenre(genre, high-1);
  271.         }
  272.         else {
  273.           givenGenre(genre, high-1);
  274.         }
  275.     }
  276.  
  277. //////////////////////////////////////////////////////////////////////////////////////////////
  278. //////////////////////////////////////////////////////////////////////////////////////////////
  279.  
  280.     public static void main(String[] args){
  281.         //Create input object of Scanner class
  282.        
  283.         String dummyS;
  284.         int dummyI;
  285.  
  286.         //Initialise array of objects of Movie class
  287.         if(index == 0){
  288.             initialiseArray();
  289.         }
  290.        
  291.         movies[index].setId(index+1);
  292.  
  293.         System.out.println("Enter Movie Name : ");
  294.         dummyS = input.nextLine();
  295.         movies[index].setName(dummyS);
  296.  
  297.         if(index == 4){
  298.             View();
  299.         }
  300.  
  301.         if(index<4){
  302.             index++;
  303.             //call mainCaller to call main method
  304.             mainCaller();
  305.         }
  306.     }
  307. }
Add Comment
Please, Sign In to add comment