//------------// Introduction to Programming Using Java: An Object-Oriented Approach//	Arnow/Weiss//------------// the "management-looks-at-the-bottom-line" song library class// Chapter 9, Section 9.8, Page 359-361// MODIFICATIONS://    Normally these classes would be in separate files, but//    we put them here in one file for convenience. We have also//    added a Song class.// We include in this directory a file, "ClassicRock" that can// be used as song library inputimport java.io.*;import java.util.*;public class BottomLine {    public static void main(String[] args) throws Exception {        String            songLibraryName;        int               maxSegmentLength;        BufferedReader    br = new BufferedReader(new InputStreamReader(System.in));        System.out.print("Name of song library: "); System.out.flush();        songLibraryName = br.readLine();        System.out.print("Maximum segment length: "); System.out.flush();        maxSegmentLength = Integer.parseInt(br.readLine());        SongLibrary s = new SongLibrary(songLibraryName);        s.makeSegments(maxSegmentLength, System.out);    }}class SongLibrary {	public SongLibrary(String songFileName) throws Exception {		songColl = new Vector();		BufferedReader br =			new BufferedReader(				new InputStreamReader(new 		FileInputStream(songFileName)));		Song song = Song.read(br);		while (song!=null) {			songColl.addElement(song);			song = Song.read(br);		}	}	public void makeSegments(int segmentLimit, PrintStream ps) {		int	segmentLength=0;    // Duration of the current segment		Song	song;             // Next song to add to segment		Enumeration    songList;  // List of songs remaining to be considered		songList = songColl.elements();		while (songList.hasMoreElements()) {			song = (Song) songList.nextElement();			if (segmentLength+song.getPlayTime() > segmentLimit)  {				ps.println("---- End of segment ----");				segmentLength = 0;			}			segmentLength += song.getPlayTime();			ps.println(song.toString());		}		if (segmentLength>0)			ps.println("---- End of segment ----");	}	Vector	songColl;}class Song {	Song(String title, String artist, int time) {		this.title = title;		this.artist = artist;		this.time = time;	}	static Song read(BufferedReader br)  throws Exception {		String title = br.readLine();		if (title==null)			return null;		String artist = br.readLine();		if (artist==null)			return null;		String time = br.readLine();		if (time==null)			return null;		return new Song(title,artist,Integer.parseInt(time));	}	int getPlayTime() { return time; }	public String toString() { return title+"("+artist+")"; }	String	title, artist;	int	time;}