jeudi 12 mars 2015

I'm trying to program something from an exercise in my Java Book, not quite getting what is being asked of me



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?




Aucun commentaire:

Enregistrer un commentaire