Maybe you should think that you need the spaces and indentation for your own purposes, but the compiler can usually cope without spacing.
Carey Brown wrote:In general, spacing doesn't matter in Java, . . .
And welcome to The Ranch.
That means there are going to be nulls in the array somewhere, and that is impossible to sort using conventional methods as taught atColleges.
Piet Souris wrote:This is an assignment, concerning possibly partly filled arrays. This is not common . . .
You can still use utility methods to sort arrays containing nulls. You can't use Comparable obects, however, because you cannot compare null references like that. You can however create a Comparator<Author> that copes well with nulls. I can't remember whether the tutorials link I gave tells you anything about nulls, nor whether the static methods in Comparable<T> that cope with nulls are permissible, but you can write a Comparator like this:-I am presuming that OP doesn't know how to turn that anonymous class into a λ. If both arguments are null, that Comparator will cause a redundant swap of the two nulls. You can sort that out by inserting a1 == a2 ? 0 : after return.
putting it in a utility class seems not obvious. But why isn't the variable 'nbrAuthors' a parameter in this case?
I am not convinced; the book cover tends to tells us at least about the author's other books.
Emily Rosemond wrote: . . . The Author class represents what you get from reading the cover of a book, nothing more, nothing less. . . . .
Do you think of people as authors of a particular genre? Dorthy L Sayers wrote mostly detective stories, but she also
What happens if one author writes different types of books, for example, a science-fiction writer might also write autobiographies of celebrities. If Author were abstract and had a ScienceFictionAuthor subclass . . .
Maybe. Or maybe that you have hit an intersting question which will come up in the JavaRanch Journal and earn you a cow.
You might think I'm stubborn, . . . trying to justify what I'm doing
You don't make an abstraction from a class. A class IS‑AN abstraction of a real‑life object already. Your class encapsulates a name, and it doesn't say what that name is. That makes it an abstraction.
but I just don't see why or how you would abstract Author when it's a simple class. . .
That sounds the same as I said a few lines back. But without some sort of information about books, or even genres, I am finding it hard to distinguish yoiur Author class from a simple Name class.
. . . Different Author types don't need to exist as subclasses or implementations.