-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicExchangeTestProgram2.java
More file actions
58 lines (49 loc) · 2.39 KB
/
MusicExchangeTestProgram2.java
File metadata and controls
58 lines (49 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.ArrayList;
public class MusicExchangeTestProgram2 {
public static void main(String args[]) {
ArrayList<String> catalog;
// Create a new music exchange center
MusicExchangeCenter mec = new MusicExchangeCenter();
// Create some users and give them some songs
User discoStew = User.DiscoStew();
User sleepingSam = User.SleepingSam();
User ronnieRocker = User.RonnieRocker();
User countryCandy = User.CountryCandy();
User peterPunk = User.PeterPunk();
// Register the users
discoStew.register(mec);
ronnieRocker.register(mec);
sleepingSam.register(mec);
countryCandy.register(mec);
peterPunk.register(mec);
// Log on all users
discoStew.logon(mec);
sleepingSam.logon(mec);
ronnieRocker.logon(mec);
countryCandy.logon(mec);
peterPunk.logon(mec);
System.out.println("Status: " + mec);
// Simulate a user requesting a list of songs
catalog = discoStew.requestCompleteSonglist(mec);
System.out.println("Complete Song List: ");
for (String s: catalog)
System.out.println(" " + s);
// Simulate a user downloading 3 songs from the list
System.out.println("\nDisco Stew before downloading: " + discoStew);
discoStew.downloadSong(mec, "Bite My Arms Off", "Peter Punk");
discoStew.downloadSong(mec, "Meadows", "Sleeping Sam");
discoStew.downloadSong(mec, "If I Had a Hammer", "Country Candy");
discoStew.downloadSong(mec, "Sandy Toes", "Country Candy");
ronnieRocker.logoff(mec); // log off Ronnie, next download should fail
discoStew.downloadSong(mec, "Only You Can Rock Me", "Ronnie Rocker");
System.out.println("Disco Stew after downloading: " + discoStew);
ronnieRocker.logon(mec); // log on Ronnie, next download should work
discoStew.downloadSong(mec, "Only You Can Rock Me", "Ronnie Rocker");
System.out.println("Disco Stew after downloading Ronnie’s: " + discoStew + "\n");
// Simulate a user requesting a list of songs by a specific artist
catalog = discoStew.requestSonglistByArtist(mec, "Jaw");
System.out.println("Song’s by Jaw: ");
for (String s: catalog)
System.out.println(" " + s);
}
}