Main
// The "CDCOLLECT" class.
import cs1.Keyboard;
public class CDCOLLECT
{
public static void main (String[] args)
{
System.out.println ("How many Cd's");
int choice = Keyboard.readInt ();
CD[] c = new CD [choice];
int index = 0, cdtracknum;
String cdname, cdartist;
boolean answer = false;
while (answer == false)
{
System.out.println ("CD # " + (index + 1));
System.out.print ("Album's Name?: ");
cdname = Keyboard.readString ();
System.out.print ("Artist's Name?: ");
cdartist = Keyboard.readString ();
System.out.print ("# of Tracks?: ");
cdtracknum = Keyboard.readInt ();
String[] trackname = new String [cdtracknum];
for (int x = 0; x < cdtracknum; x++)
{
System.out.print ("(" + (x + 1) + ")" + "Name of the Tracks?: ");
trackname [x] = Keyboard.readString ();
}
CD cd = new CD (cdname, cdartist, cdtracknum, trackname);
c [index] = cd;
if ((index + 1) == choice)
break;
index++;
System.out.println (cd); // this is where i am testing to see if it printed anything
// and it doens't print it
}
}
}
Object File
public class CD implements Comparable
{
String name, artist;
String[] trackname = new String [30];
int tracknum;
public CD (String cdname, String cdartist, int cdtracknum, String[] trackname1)
{
name = cdname;
artist = cdartist;
tracknum = cdtracknum;
// is this correct???
for (int x = 0; x < trackname1.length; x++)
{
trackname [x] = trackname1 [x];
}
}
public int compareTo (Object o)
{
return -1;
}
public String toString ()
{
return trackname [0]; // I am trying to print it out to see if it worked
}
}

New Topic/Question
Reply




MultiQuote





|