Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Re-write these three Java classes. So I'm supposed to write a program that keeps track of customers and movies in a video store. and has

Re-write these three Java classes.

So I'm supposed to write a program that keeps track of customers and movies in a video store. and has these

Specifications

You will write a program will first load customer and movie information from text files and keep the information in its memory (suggestion to use ArrayList class for database structure, but you can use any type of list/array)

Then the program will enable a video store employee to complete the following tasks:

Add a movie to the collection of movies (database) available for rent.

Find information about a movie (name, author, genre, year, and available status) by giving just movie name.

Genre includes: drama, comedy, action, and horror

Search for movies in the database with a specific genre (type) and/or from a particular year on.

Remove a movie from database by giving name, author, genre, and year as long as the movie is available.

Add a customer (name, id, checking out movie, and accumulate number of movies that customer has checked out) to the collection of customers (database) that can rent movies.

Find information about a customer.

Remove a customer from the database as long as that customer doesnt check out any movie

Rent a movie.

Return a movie.

Print all the movies in the database with sort choice by employee (by name, by author, by year, by genre)

Print all the customers in the database with sort choice by employee (by name, by id, by number of rented movies)

Assumptions

Customer' names are unique and consist of a first name and last name (no middle initial).

Movies' titles are unique.

A customer can only rent one movie and immediately pays for it.

A customer must return all movies in order to check out more

The store keeps only one copy of each movie title.

When the program is started if there is no database file, there are no customers or movies in the system.

I already have all the codes and required classes, but I need to write them in two different ways. My way is below. I can't seem to write them in other ways.

Movie class :This class represents a movie. A customer is identified by a name, author, genre, and year

public class Movie { String title; String author; int year; String genre; public Movie() { title = null; author = null; year = 0; genre =null; } public Movie (String newTitle, String newAuthor, int newYear, String newGenre) { title = newTitle; author = newAuthor; year = newYear; genre = newGenre; }

}

Customer Class: This class represents a customer. A customer is identified by a name (firstname and lastname), id, name movies that the customercurrently has rented, and accumulated number of movies that customer rented.

public class Customer { String firstname; String lastname; int id; String moviename; int numOfRentedMovie;

public Customer() { // Default Constructor firstname = null; lastname = null; id = 0; moviename = null; numOfRentedMovie = 0; }

public Customer(String newFirstname, String newLastname, int newid, String newMoviename, int newNumOfRentedMovie) { firstname = newFirstname; lastname = newLastname; id = newid; moviename = newMoviename; numOfRentedMovie = newNumOfRentedMovie; } }

VideoStore Class:

Methods (all are public methods)

o addMovie: Adds a movie to the collection of movies. The collection of movies is kept sorted by title. The method prototype is given below:

boolean addMovie(String title, String author, int year, String genre)

The year parameter represents the year the movie was released. The genre parameter refers to the film's genre (e.g., Action, Horror, Romance, etc.). This method will return true if the add operation was completed successfully and false if the movie is already part of the database.

o findMovie: Returns a String with information about the movie or null if the movie is not part of the database.

String findMovie(String title)

Throw exception NotFoundMovieException if not able to find the movie

If the movie is not currently rented, the format of the String to return is:

Title: "title", Author: author, Year: year, Genre: genre

where title, year, and genre correspond to the movie's title, year and genre. If the movie is currently rented then the format is:

Title: "title", Author: author, Year: year, Genre: genre (RENTED)

o findMovies: Returns a String with those movies that have the specified genre (e.g., Horror, Action, Romance, etc.) and that were released on or after the specified year.

String findMovies(String genre, int year)

If genre is null then the genre is ignored in the search process. If year is -1 the year value is ignored in the search process. The method will return null if no movies satisfy the search criteria. The format of the String to be returned is a sequence of movies each on a line by itself.

o addCustomer: Adds to the database the customer whose name is specified in the parameters.

boolean addCustomer(String firstName, String lastName)

Other field associated with a new customer must be initialized correctly. A unique customers id must be generated automatically (and sequentially with the highest existing customer's id). The rented movie field will be set to null, and the number of rented movies will be zero. The method will return true if the add operation was successful and false if the customer is already part of the database.

o findCustomer: Returns a String with information about a customer or null if the customer is not part of the database.

String findCustomer(String firstName, String lastName)

Note that we can pass empy string (or null string) for either field, and the function should return all possible customers which has the same name as specified by other parameter. For example:

findCustomer(Tim, null)

should return all customers have first name as Tim

The format of the String to return is one of the following. If the customer has no rented movies the result is:

Name: name, ID: id, No movies rented,#.

If the customer has rented movies the result is:

Name: name, ID: id, Movies (rented): MovieName,#.

o removeCustomer: Removes the specified customer from the database.

void removeCustomer(String firstName, String lastName)

Throw exception NotFoundCustomerException if not able to find the customer

o checkoutMovie: A reference to the specified movie is added to the array of movies associated with the specified customer.

void checkoutMovie(String firstName, String lastName, String title)

The following error conditions can arise as a result of this operation. These conditions must be tested in the following order. Once an error condition has been recognized, the method will return that condition and ignore the rest

Throw exception NotFoundCustomerException if not able to find the customer

Throw exception NotFoundMovieException if not able to find the movie

Throw exception InvalidMovieRentException if movie is current being rented

o checkinMovie: Removes the reference to the specified movie from the array of movies associated with the customer.

void checkinMovie(String firstName, String lastName, String title)

The following error conditions can arise as a result of this operation. These conditions must be tested in the following order. Once an error condition has been recognized, the method will return that condition and ignore the rest.

Throw exception NotFoundCustomerException if not able to find the customer

Throw exception NotFoundMovieException if not able to find the movie

o printAllMovies: Returns a String with all the movies in the database.

String allMovies(int criteria)

When doing printall movies, I would expect to be able teo see the list sorted by name, author, year, or genre

The format of the output string is similar as method findMovies above. A value of null will be returned if there are no movies in the database.

o printAllCustomers: Returns a String will all the customers in the database.

String allCustomers(int criteria)

When doing printall customers, I would expect to be able to see the list can be sorted by firstname, lastname, id, or the number of rented movies.

The format of the String to be returned is a sequence of customers which is the similar as findCustomer above each on a line by itself. We refer to this list as the CustomerList. A value of null will be returned if there are no customers in the database.

import java.io.*; import java.util.*;

public class VideoStore { final static String CUSTOMER_FILE_NAME = "Customers.txt"; final static String MOVIE_FILE_NAME = "Movies.txt"; private ArrayList customerList; private ArrayList movieList; private int highestid = 0;

public static void main(String[] args) { VideoStore store = new VideoStore(); // program should start by loading data file if possible. store.ReadCustomertFile(CUSTOMER_FILE_NAME); // then it will do a for loop to get user's input and perform the actions Scanner input = new Scanner (System.in);

System.out.println("Welcome to My Video Store, where you can find some great service.."); store.usage();

int choice = 0; int criteria = 0; do { System.out.println("Enter an option: "); try { choice = input.nextInt(); }catch (InputMismatchException e ) { System.out.println("get invalid input"); input.nextLine(); } switch (choice) { case 0: store.usage(); break; case 1: // the list of movies" System.out.println("What do you want to sort the list by? 1: name, 2: author, 3: year, 4: genre"); criteria = input.nextInt(); System.out.println("\t\tLIST OF ALL MOVIES "); System.out.println(store.allMovies(criteria)); break; case 2: // list of customers System.out.println("What do you want to sort the list by? 1: name, 2: id, 3: number of movie rented"); criteria = input.nextInt(); System.out.println("\t\tLIST OF ALL CUSTOMERS "); System.out.println(store.allCustomers(criteria)); break; case 3: // search for a customer; break; case 4: // search for a movie break; case 5: // add a new customer break; case 6: // add new movie break; case 7: // remove a customer break; case 8: // remove a movie break; case 9: // check in a movie break; case 10: // check out a movie break; } } while (choice < 11); System.out.println ("Thanks for visiting our store, bye ..."); input.close(); } public VideoStore() { customerList = new ArrayList(); movieList = new ArrayList(); highestid = 0; } public boolean addMovie(String title, String author, int year, String genre) { Movie tempMovie = new Movie(title, author, year, genre); movieList.add(tempMovie); return true; } public String findMovie(String title) { return null; } public static String findMovies(String genre, int year) { return null; } public boolean addCustomer(String firstName, String lastName) { Customer tempCustomer = new Customer(firstName, lastName,highestid,null,0); customerList.add(tempCustomer); return true; } public String findCustomer(String firstName, String lastName) { return null; } public void removeCustomer(String firstName, String lastName) { } public void removeMovie (String title) { } public void checkoutMovie(String firstName, String lastName, String title) { } public void checkinMovie(String firstName, String lastName, String title) { } public String allMovies(int criteria) { // This function will returns a String with all the movies in the database. String returnStr = "Function will read out list of movies, sort according to passing criteria"; return returnStr; } public String allCustomers (int criteria) { // This function will returns a String with all the customers in the database. String returnStr = "Function will read out list of customers, sort according to passing criteria"; return returnStr; } private void usage() { System.out.println("Enter 1 to see the list of movies"); System.out.println("Enter 2 to see the list of customers"); System.out.println("Enter 3 to search for a customer"); System.out.println("Enter 4 to search for a movie"); System.out.println("Enter 5 to add a new customer"); System.out.println("Enter 6 to add a new movie"); System.out.println("Enter 7 remove a customer"); System.out.println("Enter 8 remove a movie"); System.out.println("Enter 9 check in a movie"); System.out.println("Enter 10 check out a movie"); System.out.println("Enter 11 to quit"); System.out.println("Enter 0 to display this menu "); }

private void ReadCustomertFile(String filename) { // Reading a text file whose name is filename. This file contains customer's information String line = null; try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filename))) { while ((line = bufferedReader.readLine()) != null) { // each line in customer file will have // format "firstname,lastname,id,name of renting movie, number of rented movie" // System.out.println(line); String[] tokens = line.split(","); int id = Integer.parseInt(tokens[2]); int numberr = Integer.parseInt(tokens[4]); Customer tempCustomer = new Customer(tokens[0],tokens[1],Integer.parseInt(tokens[2]),tokens[3], Integer.parseInt(tokens[4])); customerList.add(tempCustomer); } } catch (IOException x) { System.err.format("IOException: %s%n", x); }

} }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What is the purpose of a balance sheet?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago