Question

Project Description Complete the Film Database program described below. This program allows users to store a...

Project Description

Complete the Film Database program described below.

This program allows users to store a list of their favorite films. To build this program, you will need to create two classes which are used in the program’s main function. The “Film” class will store information about a single movie or TV series. The “FilmCollection” class will store a set of films, and includes functions which allow the user to add films to the list and view its contents.

IMPORTANT: Remember that every class must be defined in a separate .java file, and the name of the file must match the name of the class exactly.

Film class:

This class is a simple container for information about one film. The class should contain the following public variables:

1. A string for the “title” of the film

2. A string for the film’s “description”

3. An integer “rating”

The Film class requires only one function definition: the constructor function. The constructor function should take a String “newTitle” as a parameter, used to initialize the “title” variable similar to the examples given above.

FilmCollection class:

The Film Collection class stores a set of Film objects. The class should define the following private variables:

1. An array of Film objects named “films”

2. An integer “totalFilms”

The constructor function for the FilmCollection class requires one parameter: an integer “maxFilms”, indicating the number of films the class is allowed to store. Initialize the “films” array in the constructor function, using the “maxFilms” parameter to set the size of the array.

Two other functions must be defined for the program to run:

1. void addFilm(Film f) This function should store the Film object “f” in the “films” array.

2. void printFilms() This function should print the title of each film in the “films” array.

Example Output

NOTE: Text entered by the user is shown in BOLD ITALICS

Type "add" to enter a new film

Type "display" to view all films

add

Enter a title: End Game

Saved the film "End Game"

Type "add" to enter a new film

Type "display" to view all films

add

Enter a title: Game of Thrones

Saved the film "Game of Thrones"

Type "add" to enter a new film

Type "display" to view all films

display

Film 1: End Game

Film 2: Game of Thrones

Type "add" to enter a new film

Type "display" to view all films

exit

Exiting...

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here are the 3 java classes - Film.java, FilmCollection.java and FilmDriver.java (main class)

======================================================================================

public class Film {

    private String title;
    private String description;
    private int rating;

    public Film(String title) {
        this.title = title;
        description = "";
        rating = 0;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    @Override
    public String toString() {
        return getTitle()+" "+getDescription()+" ";
    }
}

public class FilmCollection {



    private int max_films = 10;

    private Film[] films;

    private int totalFilms;





    public FilmCollection(int maxFilms) {

        this.max_films = maxFilms;

        films = new Film[maxFilms];

        totalFilms = 0;

    }



    public void addFilm(Film f) {

        if (totalFilms < max_films) {

            films[totalFilms++] = f;

            System.out.println("Saved the film \"" + f.getTitle() + "\"");

        }

    }



    void printFilms() {



        for (int count = 0; count < totalFilms; count++) {

            System.out.println("Film" + (count + 1) + ": " + films[count]);

        }



    }



}
import java.util.Scanner;



public class FilmDriver {



    public static void main(String[] args) {



        Scanner scanner = new Scanner(System.in);



        FilmCollection collection = new FilmCollection(10);



        String userChoice = "";

        while (true) {



            System.out.println("Type \"add\" to enter a new film");

            System.out.println("Type \"display\" to view all films");

            System.out.println("Type \"exit\" to exit");

            userChoice = scanner.nextLine();

            if (userChoice.equalsIgnoreCase("add")) {



                System.out.print("Enter a title: ");

                String title = scanner.nextLine();

                Film aFilm = new Film(title);

                collection.addFilm(aFilm);



            } else if (userChoice.equalsIgnoreCase("display")) {

                collection.printFilms();



            } else if (userChoice.equalsIgnoreCase("exit")) {

                System.out.println("Exiting...");

                break;

            } else {

                System.out.println("Invalid input.");

            }
        }
    }
}

==================================================================================

Add a comment
Know the answer?
Add Answer to:
Project Description Complete the Film Database program described below. This program allows users to store a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data...

    C++ Retailltem.h, Retailltem.cpp, Store.h, Store.cpp, and Driver.cpp. Description: Write a set of programs that holds data about items in a retail store. Your submission should include 5 files, Retailltem.b, Retailltem.cpp, Store, Store.cpp, and Driver.cpp 1. Retailltem class: The class should have three member variables • description (a string, represent the item's name. A name contains space) quantity (an int, represent how many current available) price (a double, item's price) Member Functions Constructor with default argument get Description getQuantity getPrice setDescription...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • C++ program Create a class Time having data members HH, MM, SS of type integer. Write...

    C++ program Create a class Time having data members HH, MM, SS of type integer. Write a C++ program to do the following: 1. Use a Constructor to initialize HH, MM, SS to 0. 2. Create two Objects of this class and read the values of HH, MM, SS from the user for both objects (Using proper member functions). 3. Use a binary + operator to add these two objects created (Store & display result using separate object). 4. Use...

  • 3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...

    3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Your program must, at least, contain a function to read and store a number into an...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • (C++ Program) 1. Write a program to allow user enter an array of structures, with each...

    (C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...

  • C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types...

    C++ ONLY Please TRAINS DESCRIPTION You are completing a program that allows for several different types of passenger trains. One train can hold only cats. Another train can hold only wizards. You are going to create a Wizard class, a Cat class, and a Train class. You are provided the driver, lab2.cpp. The Train class should be a template class where the type of passenger is the template data type. Specifications cat class Attributes: name of cat breed of cat...

  • Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to...

    Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to display several different types (classes) of objects. Let's say, we want to display three objects of type Deer, two objects of type Tree and one object of type Hill. Each of them contains a method called display. We would like to store their object references in a single array and then call their method display one by one in a loop. However, in Java,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT