$30
Object-oriented programming has advantages such as modeling problems with less complexity and more code reuse. In this experiment, you will observe these advantages by using inheritance mechanism which is an important property of object-oriented programming. By the help of this experiment, you will learn the concept of inheritance, relationships among classes by using object references, control of multiple instances of classes, access modifiers in Java.
1 Useful Information
Under this section you will find some introductory information about the OOP concepts you might use in the project. Please make your own research for more information.
1.1 Inheritance
Object-oriented programming (OOP) covers software in terms similar to those that people use to describe real-world objects. It takes advantage of class relationships, where objects of a certain class, such as a class of vehicles, have the same characteristics cars, trucks, little red wagons and roller skates have much in common. Inheritance is one of important property of OOP. OOP takes advantage of inheritance relationships, where new classes of objects are derived by absorbing characteristics of existing classes and adding unique characteristics of their own. In Java, a class (called the derived class or subclass) extends from another class (called the base class or super class).
Figure 1: A hierarchy of Vehicle class
In Figure 1, vehicle class hierarchy is seen. Vehicle class is super class of all other classes. Derived classes which are Cars and Trucks have certain common properties; all have engine, wheels, horns etc. Thus they can be grouped under a Class called Vehicles. Apart from sharing these common features, each Derived Class has its own particular features - Cars use petrol while Trucks use diesel.
2.1.1 Method Overriding
When a class extend another class, the subclass can use the super class’ methods. However sometimes the subclass should change the behavior of a method which provided by super class. The method implementation in the subclass overrides (replaces) the implementation in the super class. The method in the subclass and its corresponding method in the super class method have the same name, parameters and the same return type. That is called method overriding.
1.2 Method Overloading
Method overloading is another important concept of OOP. When programmers need more than one method with the same functionality, they don’t have to declare new methods with different names for each one. By using method overloading feature, they declare each methods with same name but with different signatures (different argument list, argument types or orders). System.out.println() is an example of overloading method in Java. This method takes float, int, double or String as arguments.
1.3 Access Modifiers
In Java, there are three access modifiers which provide access levels for classes and members of classes: private (visible to the class only), protected (visible to the package and all subclasses) and public (visible to the everywhere). The default is visible to the package.
2 Experiment
This section contains four subsections. The first section introduces the problem that you need to solve and gives its details. In the second subsection, the content of reports are described. The constraints are given in the third subsection. Information about the submission is given in the last subsection.
2.1 Problem Definition
In this experiment, you are supposed to develop a simple Movie Database System similar to IMDB. You are responsible for using inheritance mechanism and access modifiers in Java programming language. The system will process several data input files and will generate results of commands which will be read from a command input file. All input files will be error free only syntactically. The requirements and rules for the system are given below:
• The system includes information about people and films.
• Each Person has name, surname, country and a unique id. A person in the system could be either Artist or User.
• Each User has a unique id, name, surname and country.
• There are three kinds of Artist: Performer, Director and Writer. Each Director has a unique id, name, surname, country and agent where he/she works. Each Writer has a unique id, name, surname, country and writing style/type.
• There are also three types of Performers which are Actor, ChildActor and StuntPerformer. Each Actor has a unique id, name, surname, country and height. Each ChildActor has a unique id, name, surname, country and age. Each StuntPerformer has a unique id, name, surname, country, height and real actors’ ids.
• There are four types of films in the system: Feature Film, Short Film, Documentary and TV Series. Each film (Feature Film, Short Film, Documentary and TV Series) has a rating score which calculated from users’ average rating scores for that film. • A unique film id, film title, language, runtime, country, directors of a film and cast are common in all film types.
• Feature Films have a release date, budget, writers of movie and film genre in addition to the common data.
• A Short Film has a release date, writers and genre in addition to the common data. A Short Film’ runtime should be less ( or equal) than 40 min.
• Documentaries have only a release date in addition to the common film data.
• TV Series have start date and end date of series, number of seasons, number of episodes, genre of series and writers in addition to the common film data. • A film may have more than one directors, writers, performers and genres in this system. A comma will be used to separate these data.
3.1.1 The Way of Execution
The program will be executed with four command line arguments:
<people_file<films_file<commands_file<output_file
Usage example:
javac Main.java
java Main people.txt films.txt commands.txt output.txt
There are three types of data input files and one output file. All the file names will be taken as program arguments. The format of each file is given below.
3.1.2 People File
There are six different recording samples in this file. These are:
DIRECTOR:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY<tab<AGENT
WRITER:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY<tab<TYPE
ACTOR:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY<tab<HEIGHT
CHILDACTOR:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY<tab<AGE
STUNTPERFORMER:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY<tab<HEIGHT<tab
<ACTOR1ID,...,ACTORnID
USER:<tab<ID<tab<NAME<tab<SURNAME<tab<COUNTRY
An exemplar people file is shown in Figure 2. As shown in Figure 2, the person type is specified at the beginning of each line, and then attributes are given according to the person type, separated by tab characters.
3.1.3 Films File
Since there are four different film types in this system, there are also four different record samples in this file.
FeatureFilm:<tab<ID<tab<TITLE<tab<LANGUAGE<tab<DIRECTOR1ID,..,DIRECTORnID
<tab<LENGTH<tab<COUNTRY<tab<PERFORMER1ID,..,PERFORMERnID<tab<GENRE1,...,
GENREn<tab<RELEASEDATE<tab<WRITER1ID,...,WRITERnID<tab<BUDGET
ShortFilm:<tab<ID<tab<TITLE<tab<LANGUAGE<tab<DIRECTOR1ID,...,DIRECTORnID
<tab<LENGTH<tab<COUNTRY<tab<PERFORMER1ID,...,PERFORMERnID<tab<GENRE1,...,
GENREn<tab<RELEASEDATE<tab<WRITER1ID,...,WRITERnID
Documentary:<tab<ID<tab<TITLE<tab<LANGUAGE<tab<DIRECTOR1ID,...,<DIRECTORnID
<tab<LENGTH<tab<COUNTRY<tab<PERFORMER1ID,...,PERFORMERnID<tab<RELEASEDATE
TVSeries:<tab<ID<tab<TITLE<tab<LANGUAGE<tab<DIRECTOR1ID,...,DIRECTORnID
<tab<LENGTH<tab<COUNTRY<tab<PERFORMER1ID,...,PERFORMERnID<tab<GENRE1,..., GENREn<tab<WRITER1ID,...,WRITERnID<tab<STARTDATE<tab<ENDDATE<tab<SEASONS
<tab<EPISODES
An exemplar film file is given in Figure 3. In this file, the film type is specified at the beginning of each line, and then attributes are given according to the film type, separated by tab characters.
Figure 3: Sample films file
3.1.4 Commands File
All data input files (people and films) will be processed according to the commands which will be given in a commands file. The command file contains 12 types of commands whose definitions and formats are given below.
1. A user can rate a film so that film will be saved to his/her rate list. Rating score must be between 1 and 10 integers.
RATE<tab<USERID<tab<FILMID<tab<RATINGPOINT
2. It’s possible to add a new Feature Film to the system.
ADD<tabFEATUREFILM<tab<ID<tab<TITLE<tab<LANGUAGE<tab
<DIRECTOR1ID,..., DIRECTORnID<tab<LENGTH<tab<COUNTRY<tab
<PERFORMER1ID,...,PERFORMERnID <tab<GENRE1,...,GENREn<tab
<RELEASEDATE<tab<WRITER1ID,...,WRITERnID<tab <BUDGET
3. Details of a film are displayed by using below command.
VIEWFILM<tab<FILMID
4. A user can list all films which he/she rated so far.
LIST<tabUSER<tab<USERID<tabRATES
5. A user can edit a film which he/she rated before.
EDIT<tabRATE<tab<USERID<tab<FILMID<tab<NEWRATINGPOINT
6. A user can remove one of his/her rated films.
REMOVE<tabRATE<tab<USERID<tab<FILMID
7. List all the TV Series in the system.
LIST<tabFILM<tabSERIES
8. List all the films from a specified country.
LIST<tabFILMS<tabBY<tabCOUNTRY<tab<COUNTRY
9. List all the films released before a specified year.
LIST<tabFEATUREFILMS<tabBEFORE<tab<YEAR
10. List all the films released after a specified year.
LIST<tabFEATUREFILMS<tabAFTER<tab<YEAR
11. List all the films in descending order and categorized according to film rating degrees.
LIST<tabFILMS<tabBY<tabRATE<tabDEGREE
12. List all the artists from a specified country and display in a categorized order.
LIST<tabARTISTS<tabFROM<tab<COUNTRY
Figure 4: Sample commands file
3.1.5 Output File
The output of the commands will be printed to the specified output file. Each command’s output will include the command itself as read from the command file and the result (error message if necessary) of its execution. The general format of the output file is shown below:
<COMMAND
<NEWLINE
<RESULT
<NEWLINE
<_______________________________________________
Detailed format of<RESULT (mentioned above in the general format) output for each command type is given below (WS represents Whitespace).
1. Film rated successfully
Film type:<WS<FILMTYPE Film title:<WS<TITLE
If there is not any user or film with specified ID the <RESULT should be as follows:
Command Failed
User ID:<WS<USERID
Film ID:<WS<FILMID
If the specified film was already rated by the given user, then there should be a warning message as follows:
This film was earlier rated
2. FeatureFilm added successfully
Film ID:<WS<FILMID Film title:<WS<TITLE
If there is already a film with specified <FILMID or if there is not any specified director, writer or performer in the system, the <RESULT should be as follows:
Command Failed
Film ID:<WS<FILMID
Film title:<WS<TITLE
3. If specified film is Feature Film or Short Film the result will be as follows:
<TITLE<WS(<RELEASEDATE)
<GENRE
Writers:<WS<NAME<WS<SURNAME
Directors:<WS<NAME<WS<SURNAME
Stars:<WS<NAME<WS<SURNAME
<RATINGS/10 from<VOTECOUNTusers
If specified film is Documentary; since a documentary doesn’t have writers and genre in the system, the result will be as follows:
<TITLE<WS(<RELEASEDATE)
Directors:<WS<NAME<WS<SURNAME
Stars:<WS<NAME<WS<SURNAME
<RATINGS/10 from<VOTECOUNTusers
If specified film is TV Series the result will be as follows:
<TITLE<WS(<STARTDATE-<ENDDATE)
<SEASONS<WSseasons,<WS<EPISODES<WSepisodes
<GENRE
Writers:<WS<NAME<WS<SURNAME
Directors:<WS<NAME<WS<SURNAME
Stars:<WS¡NAME¿<WS<SURNAME
<RATINGS/10 from<VOTECOUNTusers
If there is not any film with specified <FILMID the <RESULT should be as follows:
Command Failed
Film ID:<WS<FILMID
If there is not any rating votes for that film, then below warning message should be printed:
Awaiting for votes
4. <TITLE:<WS <RATINGSCORE
If there is not any ratings of the specified user, then a warning message will be printed to the output file as follows:
There is not any ratings so far
If there is not any user with specified <USERID the <RESULT should be as follows:
Command Failed
User ID:<WS<USERID
5. New ratings done successfully
Film title:<WS<TITLE
Your rating:<WS<NEWRATINGSCORE
If there is not any user or film with specified IDs and if the user has no rating score for the specified film, then the <RESULT should be as follows:
Command Failed
User ID:<WS<USERID Film ID:<WS<FILMID
6. Your film rating was removed successfully
Film title:<WS<TITLE
If there is not any user or film with specified IDs and if the user has no rating score for the specified film, then the <RESULT should be as follows:
Command Failed
User ID:<WS<USERID Film ID:<WS<FILMID
7. <TITLE<WS(<STARTDATE-<ENDDATE)
<SEASONS<WSseasons and<WS<EPISODES<WSepisodes
If there is not any TV Series in the system, then a warning message will be printed to the output file as follows:
No result
8. Film title:<WS<TITLE
<LENGTH<WSmin
Language:<WS<LANGUAGE
If there is not any film for the specified country in the system, then a warning message will be printed to the output file as follows:
No result
9. Film title:<TITLE<WS(<RELEASEDATE)
<LENGTH<WSmin
Language:<WS<LANGUAGE
If there is not any film released before the specified date in the system, then a warning message will be printed to the output file as follows:
No result
10. Film title:<TITLE<WS(<RELEASEDATE)
<LENGTH<WSmin
Language:<WS<LANGUAGE
If there is not any film released after specified date in the system, then a warning mes-sage will be printed to the output file as follows:
No result
11. FeatureFilm:
<TITLE<WS(<RELEASEDATE) Ratings:<WS<RATINGS/10 from<VOTECOUNTusers
ShortFilm:
<TITLE<WS(<RELEASEDATE) Ratings:<WS<RATINGS/10 from<VOTECOUNTusers
Documentary:<TITLE<WS(<RELEASEDATE) Ratings:<WS<RATINGS/10 from<VOTECOUNTusers
TVSeries:
<TITLE<WS(<STARTDATE-<ENDDATE) Ratings:<WS<RATINGS/10 from<VOTECOUNTusers
All the results should be printed in descending order.
If there is not any result for a category, then a warning message will be printed to the output file for that category as follows:
No result
12. Directors:
<NAME<WS<SURNAME<WS<AGENT
Writers:
<NAME<WS<SURNAME<WS<TYPE
Actors:
<NAME<WS<SURNAME<WS<HEIGHT<WScm
ChildActors:
<NAME<WS<SURNAME<WS<AGE
StuntPerformers:
<NAME<WS<SURNAME<WS<HEIGHT<WScm
If there is not any result for a category, then a warning message will be printed to the output file for that category as follows:
No result
According to these definitions a sample output file is given in Figure 5 and Figure 6. This output file is not complete. The rest will be provided to you as sample input and output on the Piazza page. Further examples which give more details will be provided at the course’s Piazza page.
Figure 5: Sample output file part1
Figure 6: Sample output file part 2
2.2 Report
The structure of report is described below:
• Cover Page
• Class Diagram and Solution, describe details of your solution, stating its advantages and disadvantages technically. Draw class diagram. Show attributes and method names of each class in your diagram.
• Comments, give feedback about problem, problem description, and solution constraints. • References, give the references you used throughout your work at the end of your report.
2.3 Constraints
1. The methods’ and attributes’ names should be satisfied the most common naming conventions in Java.
2. You should model entities of the system with classes.
3. Your design will be graded. You are expected to propose a suitable design for the problem.
4. You should use inheritance mechanism and correct access modifiers.
5. All the input files and output file will be taken as command line arguments.