public void rentMovie(){
System.out.println("ENter a customer ID: ");
int ID =In.nextInt();
System.out.print("Enter a movie: ");
String name=In.nextInt();
for(Customer customer:customers){
Optional<Movie> movie = catalogue.getMoviesAvailable().stream().filter(b -> b.getTitle().equals(movieName)).findFirst();
if(movie.isPresent()) {
catalogue.getMoviesAvailable().remove(movie.get());
catalogue.getMoviesRented().add(movie.get());
customer.getCurrentlyRented().add(movie);
customer.getRentingHistory().add(movie.get());
}
}}
When I run this code I get a null pointer exception on customer.getCurrentlyRented().add(movie);
and on customer.getRentingHistory().add(movie.get());
Can you tell me how to rectify this problem?
Customer Class
public class customer{
private List<Movie> currentlyRented;
private List<Movie> rentingHistory;
public Customer(){
}
}
Catalogue Class
public class Catalogue{
private List<Movie> moviesAvailable;
private List<Movie> moviesRented;
public Catalogue(){
moviesAvailable.add(new Movie("Matrix",1999,new Genre("SciFi"),3));
moviesAvailable.add(new Movie("Jurassic Park",1993, new Genre("SciFi"),4));
}
}
While renting a movie it should also update the currently renting and renting history also on the rent movie class.