Hi! I have this JAVA project with ArrayList that I really have no idea how to ta
ID: 3771198 • Letter: H
Question
Hi! I have this JAVA project with ArrayList that I really have no idea how to tackle. It's kind of a big project and I would really appreciate any kind of help or input.
The project is: Movie Database and Renting Application using ArrayList and Files
Overview:
You will implement and test an application that acts as main-memory database containing information about movies. All the records with movie information will be stored in an ArrayList. The insertion of each movie record will be based on the movie tittle. For simplicity we will assume movie tittles consisting of one word. For example: Alien, Titanic,..
In reality, each element of the ArrayList will not have simply the movie tittle, but an Object of type Movie that has the following information:
1. Movie Tittle
2. Movie year of realease
3.Duration of the movie (minutes)
4. Number of copies available
5. A sorted ArrayList with the names of the actors
You will implement the following operations for the movie database application, using the class called the DataManager.
1. Add movie - add a new movie object to the movie database.
2.Delete movie - deletes a movie object from the movie database.
3. Insert movie - insert a movie in the database in the right lexographical order.
4. Find movie - finds the information record for a movie.
5. Find movie by actor name - finds all movies for a given actor. Returns a new ArrayList with them.
6. Find movies by year - finds all movies made in a given year. Returns a new ArrayList with them.
7. Find movies by time period - find all movies in a given time period (e.g. 1980-1985). Returns a new sorted ArrayList with all movies in the indicated time period.
8. checkIn - to return a rented movie.
9. checkOut - to rent a movie to a costumer.
10. Find movies by costumer - find all the movies rented by a given costumer.
11. Print movies in order - prints all the movies in the database in order.
12. Print customers in order - prints all the costumers in the record in order.
13. Save all the customers in order to a file.
14. Display the content of the file.
Name Class
The name class will represent the name of an actor in a movie or a customer renting. It will have two private fields, the actor's last name and the actor's first name.
Searchable Interface
The sercheable interface has a method getKey that returns the desired object from the ArrayList.
Customer Class
The customer class will have a private name object represent the customer renting the movie. It will have private ArrayList object which contains the list of Movies rented by the customer and a static customerID.
Data Manager
You must implement a Data Manager class that will mantain the ArrayList of movies. The Data Manager has the sorted ArrayList of movies as a private member, sorted ArrayList of customers as a private member. The Data Manager provides the interface to perform all the mantainance operations on the movie database. These operations were mentioned at the beggining of this document. Read the file DataManager.java
Data Base
This class will be used to test the moive database. It will generate a database of movies that will be initialized by reading the needed data from the file movie.txt and perform the allowed operations as listed above on the created database. The renting record should be saved to a file record out. It is preferred to have menu listing all the allowed operations.
Project Deliverables:
1. Report which contains the problem statement, source code, UML design of the problem showing all the interclass's relations.
They asked me to do it with at least with 5 movies and 3 users
I will greatly appreciate ANY help! Thanks!
Explanation / Answer
Movie.java
import java.util.ArrayList;
import java.util.Collections;
public class Movie implements Comparable<Movie> {
private String title;
private int yearOfRelease;
private int duration;
private int numberOfCopiesAvailable;
private ArrayList<Name> namesOfActors;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getYearOfRelease() {
return yearOfRelease;
}
public void setYearOfRelease(int yearOfRelease) {
this.yearOfRelease = yearOfRelease;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public int getNumberOfCopiesAvailable() {
return numberOfCopiesAvailable;
}
public void setNumberOfCopiesAvailable(int numberOfCopiesAvailable) {
this.numberOfCopiesAvailable = numberOfCopiesAvailable;
}
public ArrayList<Name> getNamesOfActors() {
return namesOfActors;
}
public void setNamesOfActors(ArrayList<Name> namesOfActors) {
this.namesOfActors = namesOfActors;
Collections.sort(this.namesOfActors);
}
@Override
public int compareTo(Movie movie) {
return title.compareTo(movie.getTitle());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((title == null) ? 0 : title.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Movie other = (Movie) obj;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
return true;
}
@Override
public String toString() {
return "Movie [title=" + title + ", yearOfRelease=" + yearOfRelease
+ ", duration=" + duration + ", numberOfCopiesAvailable="
+ numberOfCopiesAvailable + ", namesOfActors=" + namesOfActors
+ "]";
}
}
Name.java
public class Name implements Comparable<Name>{
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public int compareTo(Name name) {
String name1 = firstName + lastName;
String name2 = name.getFirstName() + name.getLastName();
return name1.compareTo(name2);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result
+ ((lastName == null) ? 0 : lastName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Name other = (Name) obj;
if (firstName == null) {
if (other.firstName != null)
return false;
} else if (!firstName.equals(other.firstName))
return false;
if (lastName == null) {
if (other.lastName != null)
return false;
} else if (!lastName.equals(other.lastName))
return false;
return true;
}
Customer.java
import java.util.ArrayList;
public class Customer {
private Name name;
private static String customerId;
private ArrayList<Movie> rentedMovies;
public Name getName() {
return name;
}
public void setName(Name name) {
this.name = name;
}
public static String getCustomerId() {
return customerId;
}
public static void setCustomerId(String customerId) {
Customer.customerId = customerId;
}
public ArrayList<Movie> getRentedMovies() {
return rentedMovies;
}
public void setRentedMovies(ArrayList<Movie> rentedMovies) {
this.rentedMovies = rentedMovies;
}
@Override
public String toString() {
return "Customer [name=" + name + ", rentedMovies=" + rentedMovies
+ "]";
}
}
DataManager.java
package chegg;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
public class DataManager {
private ArrayList<Movie> movies = new ArrayList<Movie>();
private ArrayList<Customer> customers = new ArrayList<Customer>();
public void addMovie(Movie movie) {
movies.add(movie);
Collections.sort(movies);
}
public void deleteMovie(Movie movie) {
movies.remove(movie);
}
public void insertMovie(Movie movie) {
for (int i = 0; i < movies.size(); i++) {
if (movie.compareTo(movies.get(i)) < 0) {
movies.add(i, movie);
break;
}
}
}
public Movie findMovie(String title) {
for (Movie movie : movies) {
if (movie.getTitle().equals(title)) {
return movie;
}
}
return null;
}
public ArrayList<Movie> findMoviesByActorName(Name actor) {
ArrayList<Movie> actorMovies = new ArrayList<>();
for (Movie movie : movies) {
if (movie.getNamesOfActors().contains(actor)) {
actorMovies.add(movie);
}
}
return actorMovies;
}
public ArrayList<Movie> findMoviesByYear(int year) {
ArrayList<Movie> yearMovies = new ArrayList<>();
for (Movie movie : movies) {
if (movie.getYearOfRelease() == year) {
yearMovies.add(movie);
}
}
return yearMovies;
}
public ArrayList<Movie> findMoviesByTimePeriod(int startYear, int endYear) {
ArrayList<Movie> yearMovies = new ArrayList<>();
for (Movie movie : movies) {
if (movie.getYearOfRelease() >= startYear
&& movie.getYearOfRelease() <= endYear) {
yearMovies.add(movie);
}
}
return yearMovies;
}
public ArrayList<Movie> findMoviesByCustomer(String customerId) {
for (Customer customer : customers) {
if (customer.getCustomerId().equals(customerId)) {
return customer.getRentedMovies();
}
}
return null;
}
public void printMoviesInOrder() {
for (Movie movie : movies) {
System.out.println(movie);
}
}
public void saveCustomers() {
PrintWriter writer;
try {
writer = new PrintWriter("the-file-name.txt", "UTF-8");
for (Customer customer : customers) {
writer.println(customer);
}
writer.close();
} catch (FileNotFoundException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
I have covered almost everything. Let me know if any doubt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.