package examples; public class CompilationCD2 extends AbstractCD { private String[] artists; public CompilationCD2(String title, String[] artists, int genre, String date, String[] titles, int length) { super(title, genre, date, length, titles); this.artists = new String[artists.length]; for(int i = 0; i < artists.length; i++) this.artists[i] = artists[i]; } public String toString() { StringBuffer str = new StringBuffer(); str.append(super.toString()); str.append('\n'); for(int i = 0; i < artists.length; i++) { str.append("title " + i + ':'); str.append(trackTitles[i]); str.append(" artist: "); str.append(artists[i]); } str.append('\n'); return str.toString(); } public boolean equals(Object o) { if(o == null) return false; if(o instanceof CompilationCD2) { CompilationCD2 cd = (CompilationCD2) o; boolean result = super.equals(o); if(!result) return false; for(int i = 0; i < artists.length; i++) if(!trackTitles[i].equals(cd.trackTitles[i]) || !artists[i].equals(cd.artists[i])) { result = false; break; } return result; } return false; } public int hashCode() { int result = super.hashCode(); for(int i = 0; i < artists.length; i++) result += artists[i].hashCode() * 31 + trackTitles[i].hashCode() * 128; return result; } public int compareTo(CompilationCD2 rhs) { int result = super.compareTo(rhs), i = 0; while(result == 0) { result = artists[i].compareTo(rhs.artists[i]); i++; } return result; } }