java编程题.英文的.关于arraylist

来源:百度知道 编辑:UC知道 时间:2024/05/13 16:18:33
TrackList should represent a list of Tracks as an ArrayList. The TrackList
constructor should initialise an empty list to which Tracks are added by a
method called addTrack. The following additional methods should be included
in TrackList:
 a method to return the number of Tracks in this TrackList;
 a method to return Track i in this TrackList:
if i < 1 or i > numberOfTracks(), an IllegalArgumentException should
be thrown;
 a method to return a String representating the total playing time in hours,
minutes and seconds of this TrackList: the String result should have
the form: "hrs:mins:secs", e.g. "1:08:09" to represent a playing time
of 1 hour, 8 minutes and 9 seconds.
 a toString method
急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 谁能告诉我啊???? 哭

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

import javax.sound.midi.Track;

public class TrackList {
List list = null;

public TrackList() {
// The TrackList constructor should initialise an empty list
this.list = new ArrayList();
}

// which Tracks are added by a method called addTrack
public void addTrack(Track track) {
this.list.add(track);
}

// a method to return the number of Tracks in this TrackList
public int numberOfTracks() {
return this.list.size();
}

// a method to return Track i in this TrackList
public Track get(int i) {
// if i < 1 or i > numberOfTracks(),
// an IllegalArgumentException should be thrown
if (i < 1 || i > numberOfTracks()) {
throw new IllegalArgumentException("parameter " + i + " is not valid.");
}
return (Track) this.list.get(i);