Having no previous programming experience whatsoever (Philosophy & Linguistics student), I've decided to take a bunch of intro to programming and Java classes. I'm at the stage where I can read code with some degree of success, but having really hard time writing something from scratch.
Currently working on a problem which is ought to simulate a bookstore, apparently - I've created a few classes and extended them to subclasses, implemented a few methods, etc. It's going good apart from this one thing.
Apologies if it's very basic (which I suspect it is!), here's the gist of it:
So the next step is to construct a method (ShowByGenre) to sort my books by genre (all comedies, then all autobiographies, etc). I have a vague idea how to implement this, but not sure what should I type in first.
ArrayList<Book> BookShelf = new ArrayList<Book>();
There are a couple ways to go about this, depending on what the requirements are. In a real world situation I would create a java.util.Comparator that could compare two book's Genre element, then I would use java.util.Collections.sort(List, Comparator) to do the sorting for me. In this case, you should read the Object Ordering Tutorial to help you learn how to use Comparables and Comparators.
But that is a real-world case where you want to rely on as much work done by other people as you can. In a learning environment you might be required to implement your own sorting algorithm. If that is the case - there is a lot on the net about the various algorithms. Your instructor probably told you the name(s) of one or more algorithm, and a little searching should help you figure out what to do. In your specific case, since you are sorting the Genre, for each book you would get the Genre's 'ordinal' - or its order in the BookGenre Enum, and use that for comparison. As a brief glimpse into what it might look like: