import java.util.*; class Song { private String title; private String artist; private int year; private int id; private static int LAST_ID; public Song() { //id += LAST_ID++; LAST_ID = LAST_ID + 1; id = LAST_ID; } public Song(String title, String artist, int year) { //this(); this.title = title; this.artist = artist; this.year = year; } public String getTitle() { return title; } public String getArtist() { return artist; } public int getYear() { return year; } public void setTitle(String value) { this.title = value; } public void setArtist(String value) { this.artist = value; } public void setYear(int year) { this.year = year; } public boolean equals(Object o) { if ( o instanceof Song) { Song other = (Song) o; return (this.title.equals(other.getTitle()) && this.artist.equals(other.getArtist()) && this.year == other.getYear()); } return false; } public String toString() { return "< " + this.title + " by " + this.artist + ", " + year + ">"; } public static void main(String args[]) { ArrayList songs = new ArrayList(); for(int i=0; i < 10; i++) { songs.add(new Song("" + i, "" + i, 2000)); } Song s = new Song("1", "1", 2000); System.out.println("Does the array contain this object: " + songs.contains(s)); System.out.println(songs); } }