Its talking about Generic Classes and saying how you can create classes of generic types that aren't String, or Integer, or Double from ArrayList where you import the ArrayList.
The book clearly states you can write fields such as this:
private ArrayList members; private ArrayList machines;
and then you can make Classes based off this in the constructor and assign them.
Exercise 4.4 says to make a private field of "library" that can hold an ArrayList of type "Book".
Exercise 4.5 asks for a local variable of cs101 that can hold an ArrayList of Student.
Then by 4.7 it wants asssignments to the library, cs101, and track variables, to create the appropriate ArrayList objects.
Here is what I wrote (not including some of the methods) adding it into an already available project within the BlueJ projects folders.
import java.util.ArrayList;
/**
* A class to hold details of audio files.
*
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
*/
public class MusicOrganizer
{
// An ArrayList for storing the file names of music files.
private ArrayList<String> files;
private ArrayList<Book> library;
private ArrayList<MusicTracks> tracks;
/**
* Create a MusicOrganizer
*/
public MusicOrganizer()
{
ArrayList<Student> cs101;
files = new ArrayList<String>();
library = new ArrayList<Book>();
cs101 = new ArrayList<Student>();
}
It tells me that it can't find the symbols for Book and MusicTracks, but I've defined them exactly the way the book defines private ArrayList members; and private ArraryList machines; so i'm confused as to how the symbols can't be found as it can't even find the symbols that are defined in my school book either, which leads me to believe that maybe its my computer?
What do you guys think?
You're telling the program that you want an Arraylist of Book objects called "Library" and an arraylist of Student objects called cs101. Now you have to create those objects/classes. You don't have to make a string class because java already has a String class that is there for you.
Book class:
public class Book{
private String name, genre, author;
//This is called a constructor that instantiates Book objects
public Book(String name, String genre, String author){
//now you build the book object by assigning THIS particular book object with the passed in values
this.name = name;
this.genre = genre;
this.author = author;
}
}
Now you would have to do the same for Student. You would also want to use access/mutator methods most likely (getters and setters).