-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicExchangeTestProgram.java
More file actions
60 lines (53 loc) · 2.59 KB
/
MusicExchangeTestProgram.java
File metadata and controls
60 lines (53 loc) · 2.59 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
59
60
public class MusicExchangeTestProgram {
public static void main(String args[]) {
// 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, except SleepingSam
discoStew.register(mec);
ronnieRocker.register(mec);
countryCandy.register(mec);
peterPunk.register(mec);
// Display the state of things before anyone logs on
System.out.println("Status: " + mec);
System.out.println("On-Line Users: " + mec.onlineUsers());
System.out.println("Available Songs: " + mec.allAvailableSongs() + "\n");
// Attempt to log on two registered users and one unregistered user
discoStew.logon(mec);
sleepingSam.logon(mec); // Should not work
ronnieRocker.logon(mec);
System.out.println("Status: " + mec);
System.out.println("On-Line Users: " + mec.onlineUsers());
System.out.println("Available Songs: " + mec.allAvailableSongs() + "\n");
// Log on two more users
countryCandy.logon(mec);
peterPunk.logon(mec);
System.out.println("Status: " + mec);
System.out.println("On-Line Users: " + mec.onlineUsers());
System.out.println("Available Songs: " + mec.allAvailableSongs());
System.out.println("Available Songs By Jaw: " +
mec.availableSongsByArtist("Jaw") + "\n");
// Log off three users (one is not even logged in)
countryCandy.logoff(mec);
discoStew.logoff(mec);
sleepingSam.logoff(mec);
System.out.println("Status: " + mec);
System.out.println("On-Line Users: " + mec.onlineUsers());
System.out.println("Available Songs: " + mec.allAvailableSongs());
System.out.println("Available Songs By Jaw: " +
mec.availableSongsByArtist("Jaw") + "\n");
// Log off the last two users
peterPunk.logoff(mec);
ronnieRocker.logoff(mec);
System.out.println("Status: " + mec);
System.out.println("On-Line Users: " + mec.onlineUsers());
System.out.println("Available Songs: " + mec.allAvailableSongs());
System.out.println("Available Songs By Jaw: " +
mec.availableSongsByArtist("Jaw") + "\n");
}
}