I am trying to create an array of type Library
, where I can store many objects of type Library
that I'll manage later. Before I get too deep, I am trying to make a print()
method on the array so that I can simply call myLibrary.print()
to print the array.
public class Library {
// Constructor
public Library() {
}
public void print() {
System.out.println("Library Sorted by Title");
}
}
public class MediaManager {
public static void main(String[] args) throws Exception {
Library myLibrary[] = new Library[100];
myLibrary.print();
}
}
I am getting an error saying that there is no print()
on Library[]
.
How would I go about printing this array? Would I just loop through the array in the main file and call a separate print on each object? If this is the case, where would I write custom methods to sort the array?
UPDATE
Requirements from my assignment: "Your program will use one array of type Library to store all information read from the input file."
"At the top level you will have a class called Library. Library will have three subclasses: Music, Book, and Movie. Music will have two subclasses: Song and Album. Book will have two subclasses: Fiction and Nonfiction. Movie, Fiction, Nonfiction, Song, and Album will not have any subclasses."
UPDATE 2
This is for a CS-101 course. I don't feel I should need to use Comparable.