class Single { //private String artist; private Song3 aSide; private Song3 bSide; Single( String _artist, Song3 _aSide, Song3 _bSide ) { if (! _artist.equals(_aSide.getArtist())) { throw new IllegalArgumentException("Artist " + _artist + "doesn't match A-side artist" + _aSide.getArtist() + "."); } this.aSide = _aSide; this.bSide = _bSide; } @Override public int hashCode() { return 23; } // public String toString( /* Single this */ ) { // return this.getTitle() + " by " + this.getArtist(); // } public String getTitle( /* Single this */ ) { return this.aSide.getTitle() + " b/w " + this.bSide.getTitle(); } public String getArtist( /* SIngle this */ ) { return this.aSide.getArtist(); } /** @return the running-time of the entire single, in seconds. */ public double getLength( /* Single this */ ) { return this.getLength(true) + 1 + this.getLength(false); } public double getLength( /* Single this */ boolean useSideA ) { return (useSideA ? this.aSide : this.bSide).getLength(); } private static void testAll() { Single tt = new Single( "Ke$ha", new Song3("Ke$ha","Tik Tok",182,true), new Song3("Ke$ha", "Up the Clock", 92, false) ); Object120.printTestMsg("Single#getTitle"); Object120.assertEquals( tt.getTitle(), "Tik Tok b/w Up the Clock" ); Object120.assertEquals( tt.getLength(), 48.0 ); Object120.assertEquals( tt.getLength(true), 23.0 ); Object120.assertEquals( tt.getLength(false), 24.0 ); } public static void main( String[] args ) { testAll(); } }