I need a program Using Java that will first load customer and movie information
ID: 3663280 • Letter: I
Question
I need a program Using Java that 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:
1- Add a movie to the collection of movies (database) available for rent.
2- Find information about a movie (name, author, genre, year, and available status) by giving just movie name.
3. Genre includes: drama, comedy, action, and horror
4. Search for movies in the database with a specific genre (type) and/or from a particular year on.
5. Remove a movie from database by giving name, author, genre, and year as long as the movie is available.
6- 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.
7. Find information about a customer.
8- Remove a customer from the database as long as that customer doesn’t check out any movie
9- Rent a movie.
10- Return a movie.
11- Print all the movies in the database with sort choice by employee (by name, by author, by year, by genre)
12- Print all the customers in the database with sort choice by employee (by name, by id, by number of rented movies)
The program must have three classes
Customer.java
Movie.java
VideoStore.java this class must include the following
Explanation / Answer
VideoLibraryMain.java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class VideoLibraryMain {
static VideoStore objVideo=new VideoStore();
public void readData()
{
Movie objMovie;
Customer objCust;
try
{
//Open Movie file..
BufferedReader br = new BufferedReader(new FileReader("d://movies.txt"));
String inpLine = br.readLine();
while(inpLine != null)
{
String[] data = inpLine.split("\s+");
objMovie=new Movie(Integer.parseInt(data[0]), data[1], data[2], data[3], Integer.parseInt(data[4]), Boolean.parseBoolean(data[5]));
objVideo.setMovies(objMovie);
inpLine = br.readLine();
}
br = new BufferedReader(new FileReader("d://customers.txt"));
inpLine = br.readLine();
while(inpLine != null)
{
String[] data = inpLine.split("\s+");
objCust=new Customer(Integer.parseInt(data[0]), data[1], data[2]);
objVideo.setCustomers(objCust);
inpLine = br.readLine();
}
}
catch (IOException exception) {
System.out.println("Could not read from input file!");
System.exit(1);
}
}
public void addMovie(Movie mo)
{
objVideo.setMovies(mo);
}
public void movieInfo(String movieName)
{
for(Movie m:objVideo.getMovies())
{
if(m.getName().equals(movieName))
{
System.out.println("Movie Name : "+m.getName()+" Author : "+m.getAuthor()+" Genre : "+m.getGenre()+" Year : "+m.getYear());
if(m.isAvailableStatus())
System.out.println("Available : Yes");
else
System.out.println("Available : No");
}
}
}
public void searchMovie(Genre genre)
{
for(Movie m:objVideo.getMovies())
{
if(m.getGenre().equals(genre))
{
System.out.println("Movie Name : "+m.getName()+" Author : "+m.getAuthor()+" Genre : "+m.getGenre()+" Year : "+m.getYear());
if(m.isAvailableStatus())
System.out.println("Available : Yes");
else
System.out.println("Available : No");
}
}
}
public void searchMovie(int year)
{
for(Movie m:objVideo.getMovies())
{
if(m.getYear()==year)
{
System.out.println("Movie Name : "+m.getName()+" Author : "+m.getAuthor()+" Genre : "+m.getGenre()+" Year : "+m.getYear());
if(m.isAvailableStatus())
System.out.println("Available : Yes");
else
System.out.println("Available : No");
}
}
}
public void searchMovie(int year, Genre genre)
{
for(Movie m:objVideo.getMovies())
{
if(m.getYear()==year&&m.getGenre().equals(genre))
{
System.out.println("Movie Name : "+m.getName()+" Author : "+m.getAuthor()+" Genre : "+m.getGenre()+" Year : "+m.getYear());
if(m.isAvailableStatus())
System.out.println("Available : Yes");
else
System.out.println("Available : No");
}
}
}
public static void main(String[] args)
{
VideoLibraryMain obj=new VideoLibraryMain();
obj.readData();
obj.searchMovie(Genre.horror);
obj.searchMovie(2010, Genre.action);
Movie m=new Movie(3, "Fast & Furious", "Leo Caprio", "action", 2015, true);
obj.addMovie(m);
obj.searchMovie(2015);
obj.readData();
}
}
VideoStore.java
import java.util.ArrayList;
public class VideoStore
{
private ArrayList<Movie> movies=new ArrayList<Movie>();
private ArrayList<Customer> customers=new ArrayList<Customer>();
public ArrayList<Movie> getMovies() {
return movies;
}
public ArrayList<Customer> getCumstomers() {
return customers;
}
public void setMovies(Movie movies) {
this.movies.add(movies);
}
public void setCustomers(Customer cumstomers) {
this.customers.add(cumstomers);
}
}
Movie.java
public class Movie {
private int movieId;
private String name;
private String author;
private String genre;
private int year;
private boolean availableStatus;
public Movie(int movieId,String name, String author, String genre, int year,
boolean availableStatus) {
this.movieId=movieId;
this.name = name;
this.author = author;
this.genre = genre;
this.year = year;
this.availableStatus = availableStatus;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public String getGenre() {
return genre;
}
public int getYear() {
return year;
}
public boolean isAvailableStatus() {
return availableStatus;
}
public void setName(String name) {
this.name = name;
}
public void setAuthor(String author) {
this.author = author;
}
public void setGenre(String genre) {
this.genre = genre;
}
public void setYear(int year) {
this.year = year;
}
public void setAvailableStatus(boolean availableStatus) {
this.availableStatus = availableStatus;
}
public int getMovieId() {
return movieId;
}
public void setMovieId(int movieId) {
this.movieId = movieId;
}
}
Customer.java
public class Customer
{
private int custId;
private String custName;
private String custAddress;
public Customer(int custId, String custName, String custAddress) {
this.custId = custId;
this.custName = custName;
this.custAddress = custAddress;
}
public int getCustId() {
return custId;
}
public String getCustName() {
return custName;
}
public String getCustAddress() {
return custAddress;
}
public void setCustId(int custId) {
this.custId = custId;
}
public void setCustName(String custName) {
this.custName = custName;
}
public void setCustAddress(String custAddress) {
this.custAddress = custAddress;
}
}
Genre.java
public enum Genre {
drama, comedy, action, horror
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.