







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








import static org.junit.Assert.; import org.junit.Test; public class SongTest { }*
@Test public void testGetters() { }
public Song(String songArtist, String songTitle) { } public String getTitle() { return null; } public String getArtist() { return null; } }
public class Song { // Instance variables to remember the artist and title private String artist; private String title; public Song(String songArtist, String songTitle) { // Let each object remember these values artist = songArtist; title = songTitle; } public String getTitle() { return title; } public String getArtist() { return artist; } }
Play a Song Only Five Times per Day
public boolean canPlayToday() {
@Test public void testCanPlayTodayWithUpTo5Plays() { Song aSong = new Song("Beatles", "Help"); aSong.recordOnePlay(); assertTrue(aSong.canPlayToday()); aSong.recordOnePlay(); assertTrue(aSong.canPlayToday()); aSong.recordOnePlay(); assertTrue(aSong.canPlayToday()); aSong.recordOnePlay(); assertTrue(aSong.canPlayToday()); aSong.recordOnePlay(); // This song has been played 5 times already assertFalse(aSong.canPlayToday()); }
public void recordOnePlay() { }
public void recordOnePlay() {
// Create an empty list that can store GregorianCalendar objects GregorianCalendar[] datesPlayed = new GregorianCalendar[5]; int n = 0; // Add 3 dates objects as set in the computer's clock datesPlayed[n] = new GregorianCalendar(); n++; datesPlayed[n] = new GregorianCalendar(); n++; datesPlayed[n] = new GregorianCalendar();
for (int index = 0; index < 3; index++) { System.out.println(datesPlayed[index].getTime()); } Fri Aug 11 19:46:35 MST 2006 Fri Aug 11 19:46:35 MST 2006 Fri Aug 11 19:46:35 MST 2006
public boolean equals (Object obj) Compares this GregorianCalendar to the specified Object. The result is true if and only if the argument is a GregorianCalendar object that represents the same time value (millisecond offset from the Epoch) under the same Calendar parameters and Gregorian change date as this object.
datesPlayed = new GregorianCalendar[ 750 ];
Refactoring
// Let someone know how many times this Song has played on the current date private int getTimesPlayedToday() {