Question

In: Computer Science

Problem Write a movie management system using object-oriented design principles. The program will read from the...

Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the following options: 1. Add a new movie and save. o The user will be prompted to enter the duration in minutes, title of the new movie, and the year the movie was released. Before the movie is added, the inputs provided by the user should be validated:  The duration and year of the movie should not be zero and the title of the movie should not be empty. o When you add a new movie, the program should update the data file by saving the new movie at the end of the movie list. 2. Generate list of movies released in a year. o The user will input a year and the program will display a list of all the movies released in that year along with the duration (in minutes) of all the movies. o The list of movies does not have to be sorted. 3. Generate list of random movies. o The user will input the number of movies and the program will display a list containing the amount of random movies along with the duration (in minutes) of all the movies. o There is no minimum or maximum duration for the movies in the list. o You can use Collections.shuffle in the java.utils package to randomize the movie list. 4. Exit the program. - Save the list of movies back into the data file “movies.txt” using the above format (Duration,Title,Year). Notes: To follow the object-oriented principles, your project should contain ONLY the following classes and methods in their respective package. Package Class Methods sait.mms.application AppDriver main sait.mms.managers MovieManagementSystem displayMenu, addMovie,generateMovieInYear, generateRandomMovie, loadMovie sait.mms.problemdomain Movie Accessor methods, toString You cannot use parallel and/or nested arrays in this assignment (you can use ArrayList). Sample runs: An example of an added and saved a new movie (where input is shown in bold underline): Movie Management system 1 Add New Movie and Save 2 Generate List of Movies Released in a Year 3 Generate List of Random Movies 4 Exit Enter an option: 1 Enter duration: 100 Enter movie title: We are Gold Enter year: 2019 Saving movies... Added movie to the data file. An example of a generated list of movies released in a year (where input is shown in bold underline): Movie Management system 1 Add New Movie and Save 2 Generate List of Movies Released in a Year 3 Generate List of Random Movies 4 Exit Enter an option: 2 Enter in year: 1996 Movie List Duration Year Title 103 1996 DragonHeart 93 1996 Trainspotting 145 1996 Independence Day Total duration: 341 minutes An example of invalid option (where input is shown in bold underline): Movie Management system 1 Add New Movie and Save 2 Generate List of Movies Released in a Year 3 Generate List of Random Movies 4 Exit Enter an option: 5 Invalid option! An example of a generated list of random movies (where input is shown in bold underline): Movie Management system 1 Add New Movie and Save 2 Generate List of Movies Released in a Year 3 Generate List of Random Movies 4 Exit Enter an option: 3 Enter number of movies: 5 Movie List Duration Year Title 129 2016 Now You See Me 2 139 1999 Fight Club 136 2014 Captain America: The Winter Soldier 81 1995 Toy Story 103 2017 Life Total duration: 588 minutes

Solutions

Expert Solution

Please find your solution below and if any doubt or need changes comment and do uovote.

testMovie.java

import java.io.File;
import java.io.FileWriter;
import java.util.*;
public class testMovie {
    public static void main(String[] args) throws Exception{
                Scanner sc=new Scanner(new File("movies.txt"));
                ArrayList<Movie>list=new ArrayList<Movie>();
                String title;
                int duration;
                int year;
                while(sc.hasNext()){
                        String s=sc.nextLine();
                        String a[]=s.split(",");
                        Movie mObj=new Movie(Integer.parseInt(a[0]),a[1],Integer.parseInt(a[2]));
                        list.add(mObj);
                }
                
                sc.close();
                sc=new Scanner(System.in);
                
                while(true) {
                        System.out.println("Movie Management system");
                        System.out.println("1.Add New Movie and Save");
                        System.out.println("2.Generate List of Movies Released in a Year");
                        System.out.println("3.Generate List of Random Movies");
                        System.out.println("4.Exit the program");
                        int ch;
                        System.out.println("Enter an option: ");
                        ch=sc.nextInt();
                        switch(ch) {
                        
                        case 1:
                                {
                                        
                                        while(true) {
                                                System.out.print("Enter duration:");
                                                duration=sc.nextInt();
                                                if(duration<=0) {
                                                        System.out.println("Duration must be greater than 0");
                                                }
                                                else {
                                                        break;
                                                }
                                        }
                                        sc.nextLine();
                                        do {
                                                   System.out.print("Enter Movie Title :");
                                   title=sc.nextLine();
                                   if(title.isEmpty())
                                   {
                                       System.out.println("Title must not be empty");
                                   }
                                        }while(title.isEmpty());
                                        
                                        while(true) {
                                                System.out.print("Enter year:");
                                                year=sc.nextInt();
                                                if(year<=0) {
                                                        System.out.println("Year must be positive");
                                                }
                                                else {
                                                        break;
                                                }
                                        }
                                        Movie obj=new Movie(duration,title,year);
                                        list.add(obj);
                                        System.out.println("Saving movies... Added movie to the data file");
                                        break;
                                }
                        
                        case 2:
                        {
                                System.out.print("Enter year:");
                                year=sc.nextInt();
                                System.out.printf("%25s%n","Movie List");
                                System.out.printf("%12s","Duration");
                                System.out.printf("%12s","Year");
                                System.out.printf("%20s","Title");
                                System.out.println();
                                for(int i=0;i<list.size();i++) {
                                        if(list.get(i).getYear()==year) {
                                                System.out.printf("%12d",list.get(i).getDuration());
                                                System.out.printf("%12d",list.get(i).getYear());
                                                System.out.printf("%20s",list.get(i).getTitle());
                                                System.out.println();
                                        }
                                }
                                break;
                        }
                        case 3:
                        {
                                Random ran=new Random();                        
                                int n;
                                while(true) {
                                        System.out.print("Enter number of movies:");
                                         n=sc.nextInt();
                                        if(list.size()<n) {
                                                System.out.println("Number of movies should be less the list.");
                                        }
                                        else {
                                                break;
                                        }
                                }
                                System.out.printf("%25s%n","Movie List");
                                System.out.printf("%12s","Duration");
                                System.out.printf("%12s","Year");
                                System.out.printf("%20s","Title");
                                System.out.println();
                                for(int i=0;i<n;i++) {
                                        Collections.shuffle(list);
                                        int rand=ran.nextInt(list.size());
                                        System.out.printf("%12d",list.get(rand).getDuration());
                                        System.out.printf("%12d",list.get(rand).getYear());
                                        System.out.printf("%20s",list.get(rand).getTitle());
                                        System.out.println();
                                }
                                break;
                        }
                        case 4:
                        {
                                FileWriter wrt=new FileWriter(new File("movies.txt"));
                                for(int i=0;i<list.size();i++) {
                                        wrt.write(list.get(i).getDuration()+","+list.get(i).getTitle()+","+list.get(i).getYear()+"\n");
                                }
                                wrt.close();
                                System.exit(0);
                        }
                        default:
                                System.out.println("Invalid Option");
                                break;
                                
                        }
                }
        }
}

Movie.java

public class Movie {
   private int duration;
   private String title;
   private int year;

   /**
   * @param duration
   * @param title
   * @param year
   */
   public Movie(int duration, String title, int year) {
       this.duration = duration;
       this.title = title;
       this.year = year;
   }

   /**
   * @return the duration
   */
   public int getDuration() {
       return duration;
   }

   /**
   * @param duration
   * the duration to set
   */
   public void setDuration(int duration) {
       this.duration = duration;
   }

   /**
   * @return the title
   */
   public String getTitle() {
       return title;
   }

   /**
   * @param title
   * the title to set
   */
   public void setTitle(String title) {
       this.title = title;
   }

   /**
   * @return the year
   */
   public int getYear() {
       return year;
   }

   /**
   * @param year
   * the year to set
   */
   public void setYear(int year) {
       this.year = year;
   }

   
   

}

movies.txt

120,Saving Pirate Ryan,1998
110,Tenet,2008
120,Titanic,1996
102,The Big Bang Theory,2008
132,Thin Red Line,2002
121,The Lion king,2008
155,Avatar,2010
129,Henkok,2008
110,Mela,2011
140,Aliens,1988
120,Rock on the tent,1999
70,The Kobra of Amazon,2008
91,Gravity,2013
90,Koyla,2008
130,Terminator,1994
135,Enemy At the gates,2001


Related Solutions

Write a C++ program that will use good object-oriented principles. You have been tasked to write...
Write a C++ program that will use good object-oriented principles. You have been tasked to write an application that will allow a user to change their system password. The XYZ Corporation has the following rules for passwords: each password should have a minimum of 8 characters each password should have a minimum of 2 uppercase characters (A - Z) each password should have a minimum of 2 lowercase characters (a - z) each password should have a minimum of 2...
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
Explain Basic Characteristics of Object Oriented System Analysis & Design.
Explain Basic Characteristics of Object Oriented System Analysis & Design.
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the...
PROBLEM STATEMENT: Using the list container from the STL, write a program that will read the information from a file into a list and then display the list to the screen. Add your name. Sort the list by id. Print the list again CODE: Use the provided disneyin2.txt file. Do not hard code the file name; get file name from user. Use the struct below struct student { char firstnm[20], lastnm[20]; int id, grade; }; You are to create a...
PHP You will be using the object oriented features of PHP to design a music album...
PHP You will be using the object oriented features of PHP to design a music album processing page. First you will build a form page called addAlbum.php. This form will contain text fields for album title, artist, publisher (Sony, BMI, etc.) and genre. Add two more fields of your choice. You will post this form to the file process.php. If all the fields have values, we will create a new Album object and print the details of the object. You...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must be...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must...
design a program that solves matrices by the method of gauss-seidel use the object-oriented language c...
design a program that solves matrices by the method of gauss-seidel use the object-oriented language c ++
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop...
Using the various Object Oriented Programming concepts and skills learnt in this course, design and develop a Java Application to compute an individual student’s GPA and store the records in a database. The application should have two components i.e. The student and the course components. The following should be the minimal operations on the course component: – Set course information – Print course information – Show credit hours – Show course number The following should be the minimal operations on...
In this program, you are modifying given code so that the class is object-oriented. 2. Write...
In this program, you are modifying given code so that the class is object-oriented. 2. Write a Java class called CityDistancesOO in a class file called CityDistancesOO.java.    3. Your class will still make use of two text files. a. The first text file contains the names of cities with the first line of the file specifying how many city names are contained within the file.    b. The second text file contains the distances between the cities in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT