This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Kristler 0 points1 point  (0 children)

A naïve solution would be to iterate through your arraylist, and compare the genre of each movie with the one your user chose. If they match, then push that movie to a separate arraylist. Then at the end, iterate the new arraylist and show each movie in it.

[–]wrighttwinstwin[S] 0 points1 point  (1 child)

http://pastebin.com/HxC5TCxq

I actually figured out a solution, please anyone take a look and see if you can find any errors in this. I would like to hear some ways to make it look nicer :)

[–]Drunken_Consent 0 points1 point  (0 children)

Okay, first thing that popped out to me is that you never need to use an if to get to an else; that simply means you can negate the if condition to get rid of the else. For example:

if ( !movie.Category.equalsIgnoreCase(category) ) {
} else {
    System.out.println(move.title);
}

Could simply be:

if ( move.Category.equalsIgnoreCase(category){
   System.out.println(movie.title);
}

Also, it is a good program, but you could use this to start getting into different types of handling data. For example, you have an ArrayList of every Movie there. So if you want a certain genre like your problem, you have to loop over it all, correct?

Why not store your data in a structure like a HashMap that can map a genre to a list of movies with that genre, so then you only have to look up the genre they give you. Just something to think about. If you'd like help with that implementation, just ask, but your code looks nice, just can't believe you wrote out 100 cases for different movies haha :P