tiffprag

MovieDriverFullCode(Draft)

Jan 20th, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. import java.util.Scanner;   //Used in Driver file
  2.  
  3. //Movie class 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 void setDuration(int dur){
  43.         duration = dur;
  44.     }
  45.  
  46.     public void setAgeRating(String ageR){
  47.         ageRating = ageR;
  48.     }
  49.  
  50.     public void setDescription(String desc){
  51.         description = desc;
  52.     }
  53.  
  54.     public void displayRow(){
  55.         System.out.print("| ");
  56.         // System.out.printf("%2.2s", id);
  57.         // System.out.print(" | ");
  58.         // System.out.printf("%30.30s", name);
  59.         // System.out.println("");
  60.  
  61.         System.out.printf("%-2s %-30s %n", id, name);
  62.     }
  63.  
  64.     public void displayDetails(){
  65.         System.out.println("Movie Id : " + id);
  66.         System.out.println("Movie Name : " + name);
  67.         System.out.println("Genre : " + genre);
  68.         System.out.println("Duration : " + duration);
  69.         System.out.println("Age Rating : " + ageRating);
  70.         System.out.println("Description : \n" + description);
  71.     }
  72.  
  73. //////////////////////////////////////////////////////////////////////////////////////////////
  74. //////////////////////////////////////////////////////////////////////////////////////////////
  75.  
  76.     //In Movie Driver file
  77.     //Global Variable
  78.     public static int size = 5;
  79.     public static Movie movies[] = new Movie[size];
  80.     public static int index = 0;
  81.  
  82.     public static void initialiseArray(){
  83.         for(int i = 0; i<size; i++){
  84.             movies[i] = new Movie();
  85.         }
  86.     }
  87.  
  88.     static void mainCaller()
  89.     {
  90.             // Calling the main method
  91.             main(null);
  92.     }
  93.  
  94.     public static void main(String[] args){
  95.         //Create input object of Scanner class
  96.         Scanner input = new Scanner(System.in);
  97.         String dummyS;
  98.         int dummyI;
  99.  
  100.         //Initialise array of objects of Movie class
  101.         if(index == 0){
  102.             initialiseArray();
  103.         }
  104.        
  105.         movies[index].setId(index+1);
  106.  
  107.         System.out.println("Enter Movie Name : ");
  108.         dummyS = input.nextLine();
  109.         movies[index].setName(dummyS);
  110.  
  111.         if(index == 4){
  112.             System.out.printf("%-1 %-3s %-50s %-20s %-11s %-1 %n", "|", "ID", "Name", "Genre","Age Rating");
  113.             System.out.print(" |");
  114.             System.out.printf(
  115.             for(int i = 0; i<size; i++){
  116.                 movies[i].displayRow();
  117.             }
  118.         }
  119.  
  120.         if(index<4){
  121.             index++;
  122.             //call mainCaller to call main method
  123.             mainCaller();
  124.         }
  125.     }
  126. }
Add Comment
Please, Sign In to add comment