tiffprag

Movie Full Code(2)

Jan 21st, 2020
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.80 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.     //Main Menu : View
  109.     public static void View(){
  110.         char choice;
  111.         System.out.println("❖--------------------◂View▸--------------------❖");
  112.         System.out.println(" 1. View all.....................(Table Format)");
  113.         System.out.println(" 2. List all by Genre............(Table Format)");
  114.         System.out.println(" 3. List all by Age Rating.......(Table Format)");
  115.         System.out.println(" 4. Search by Name............(Detailed Format)");
  116.         System.out.println(" 5. Go Back......................(To Main Menu)");
  117.         System.out.println("*--------------------<****>--------------------*\n");
  118.  
  119.         System.out.print("Please enter your choice : ");
  120.         choice = input.next().charAt(0);
  121.  
  122.         clearScreen();
  123.  
  124.          switch(choice){
  125.             //View All
  126.             case '1':
  127.                 //Title
  128.                 System.out.printf("%49s %n","View All");
  129.  
  130.                 //Table Border
  131.                 System.out.print("◤");
  132.                 for(int i = 0; i<89; i++){
  133.                     System.out.print("=");
  134.                 }
  135.  
  136.                 System.out.println("◥");
  137.  
  138.                 //Table Header
  139.                 System.out.printf("%-1s %-3s %-50s %-20s %-11s %-1s %n", "|", "ID", "Name", "Genre","Age Rating", "|");
  140.                
  141.                 //Table Divider
  142.                 System.out.print("|");
  143.                 for(int i = 0; i<89; i++){
  144.                     System.out.print("=");
  145.                 }
  146.                 System.out.println("|");
  147.  
  148.                 //Display each row of recorded movies
  149.                 for(int i = 0; i<size; i++){
  150.                     movies[i].displayRow();
  151.                 }
  152.  
  153.                 //Table Border
  154.                 System.out.print("◣");
  155.  
  156.                 for(int i = 0; i<89; i++){
  157.                     System.out.print("=");
  158.                 }
  159.  
  160.                 System.out.println("◢");
  161.  
  162.                 //Pause screen before clearing
  163.                 System.out.print("\nPress enter to continue...");
  164.                 pause = input.nextLine();
  165.                 pause = input.nextLine();
  166.  
  167.                 clearScreen();
  168.  
  169.                 mainCaller();
  170.  
  171.             //List all by Genre
  172.             case '2':
  173.                 String genre;
  174.                 boolean valid = true;
  175.  
  176.                 do{
  177.                     System.out.println("*-------------------<Genres>-------------------*");
  178.                     System.out.println(" 1. Action          2. Adventure");
  179.                     System.out.println(" 3. Comedy          4. Drama");
  180.                     System.out.println(" 5. Horror          6. Sci-Fi");
  181.                     System.out.println(" 7. Romance         8. Others");
  182.                     System.out.println(" 9. Go Back.....................(To View Menu)");
  183.                     System.out.println("*-------------------<******>-------------------*\n");
  184.  
  185.                     if(!valid){
  186.                         System.out.print("'" + choice + "' is an invalid choice.\n\n");
  187.                     }
  188.  
  189.                     valid = true;
  190.  
  191.                     System.out.print("Please enter your choice : ");
  192.                     choice = input.next().charAt(0);
  193.                     switch(choice){
  194.                         case '1':
  195.                             genre = "Action";
  196.                             break;
  197.  
  198.                         case '2':
  199.                             genre = "Adventure";
  200.                             break;
  201.  
  202.                         case '3':
  203.                             genre = "Comedy";
  204.                             break;
  205.  
  206.                         case '4':
  207.                             genre = "Drama";
  208.                             break;
  209.  
  210.                         case '5':
  211.                             genre = "Horror";
  212.                             break;
  213.  
  214.                         case '6':
  215.                             genre = "Sci-Fi";
  216.                             break;
  217.  
  218.                         case '7':
  219.                             genre = "Romance";
  220.                             break;
  221.  
  222.                         case '8':
  223.                             genre = "Others";
  224.                             break;
  225.  
  226.                         case '9':
  227.                             clearScreen();
  228.                             View();
  229.  
  230.                         default:
  231.                             clearScreen();
  232.                             valid = false;
  233.                     }
  234.                 }while(!valid);
  235.  
  236.                 break;
  237.  
  238.             //List all by Age Rating
  239.             case '3':
  240.  
  241.             break;
  242.  
  243.             //Search by Name
  244.             case '4':
  245.  
  246.             break;
  247.  
  248.             //Go Back to Main Menu
  249.             case '5':
  250.                 mainCaller();
  251.  
  252.             default:
  253.                 System.out.println("'" + choice + "' is an invalid choice.");
  254.                 View();
  255.          }
  256.  
  257.     }
  258.  
  259.     //List all by Genre
  260.     void givenGenre(String genre, int high){
  261.         if (high < 0){
  262.           return;
  263.         }
  264.         else if (genre == movies[high].getGenre() ){
  265.           movies[high].displayRow();
  266.           givenGenre(genre, high-1);
  267.         }
  268.         else {
  269.           givenGenre(genre, high-1);
  270.         }
  271.     }
  272.  
  273. //////////////////////////////////////////////////////////////////////////////////////////////
  274. //////////////////////////////////////////////////////////////////////////////////////////////
  275.  
  276.     public static void main(String[] args){
  277.         //Create input object of Scanner class
  278.        
  279.         String dummyS;
  280.         int dummyI;
  281.  
  282.         //Initialise array of objects of Movie class
  283.         if(index == 0){
  284.             initialiseArray();
  285.         }
  286.        
  287.         movies[index].setId(index+1);
  288.  
  289.         System.out.println("Enter Movie Name : ");
  290.         dummyS = input.nextLine();
  291.         movies[index].setName(dummyS);
  292.  
  293.         if(index == 4){
  294.             View();
  295.         }
  296.  
  297.         if(index<4){
  298.             index++;
  299.             //call mainCaller to call main method
  300.             mainCaller();
  301.         }
  302.     }
  303. }
Add Comment
Please, Sign In to add comment