英文的java编程题 关于Arraylist

来源:百度知道 编辑:UC知道 时间:2024/05/10 17:55:58
The class CDdetails should have three fields: one for the name of the artist
or band, one for the title of the CD and one for the list of tracks. Accessor
methods for the first two fields should be provided. In addition, CDdetails
should also provide the following methods:
 a method to return the number of tracks on the CD;
 a method to return Track i on the CD:
if i < 1 or i > numberOfTracks(), an exception should be thrown;
 a method to return a String representing the total playing time in hours,
minutes and seconds of the CD (format of the String result as above);
 a toString method giving the name of the artist, the title of the CD, the
number of tracks and the total playing time of the CD.
 a method giving the same details as the above toString method but in
addition a full listing of all of the tracks on the CD, including playing
times.
(v) Class AlbumList is to represent a collection of CDs and sho

import java.util.ArrayList;
import java.util.List;

import javax.sound.midi.Track;

public class CDdetails {

// The class CDdetails should have three fields
// one for the name of the artist or band,
String name;

// one for the title of the CD
String title;

// one for the list of tracks
TrackList tracks;

// Accessor methods for the name field should be provided.
public String getName() {
return name;
}

// Accessor methods for the title field should be provided.
public String getTitle() {
return title;
}

// a method to return the number of tracks on the CD
public int numberOfTracks() {
return this.tracks.numberOfTracks();
}

// a method to return Track i on the CD
public Track getTrack(int i) throws Exception {
// if i < 1 or i > numberOfTracks(), an exception should be thrown