import java.util.*;
public class CourseAnnouncementList {
	private Vector caList; // the list of course announcements.
		// new (later) announcements appear at the end of caList

	public CourseAnnouncementList(){
		caList=new Vector();
	}

	// Add ca to the end of the course announcement list
	public void add(CourseAnnouncement ca){
		caList.add(ca);
	}

	// Return the middle course announcement, null if there isn't one
	// break ties towards the beginning of the list (earlier announcements).
	// i.e. if the list consists of [a0, a1, a2, a3] then getMiddle() returns a1
	public CourseAnnouncement getMiddle(){
		CourseAnnouncement middle=null;
		int size=caList.size();
		if(size>0){
			middle=(CourseAnnouncement)caList.elementAt(size/2);
		}
		return(middle);
	}
	
	// Return a string representation of the course announcements.
	// later announcements appear first
	public String toString(){
		String s="";
		// Scan course announcements list in reverse order
		// appending to the end of s
		for(int i=caList.size()-1;i>=0;i--){
			CourseAnnouncement ca=(CourseAnnouncement)caList.elementAt(i);
			s+=ca.toString()+"\n";
		}
		return(s);
	}

	// Print out a string representation of this course announcement
	public void print(){ System.out.println(toString()); }

	// Expire all announcements with number n (see class CourseAnnouncement)
	// We assume that an announcement number can appear more than one time.
	public void expire(int n){
		for(int i=0;i<caList.size();i++){
			CourseAnnouncement ca=(CourseAnnouncement)caList.elementAt(i);
			if(ca.getNumber()==n)ca.expire();
		}
	}
}

