Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Methods for an Array of Custom Objects in Java
    primarykey
    data
    text
    <p>I am trying to create an array of type <code>Library</code>, where I can store many objects of type <code>Library</code> that I'll manage later. Before I get too deep, I am trying to make a <code>print()</code> method on the array so that I can simply call <code>myLibrary.print()</code> to print the array.</p> <pre><code>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(); } } </code></pre> <p>I am getting an error saying that there is no <code>print()</code> on <code>Library[]</code>.</p> <p>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?</p> <p><strong>UPDATE</strong></p> <p>Requirements from my assignment: "Your program will use one array of type Library to store all information read from the input file." </p> <p>"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."</p> <p><strong>UPDATE 2</strong></p> <p>This is for a CS-101 course. I don't feel I should need to use Comparable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload