-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.java
71 lines (61 loc) · 1.64 KB
/
User.java
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
61
62
63
64
65
66
67
68
69
70
71
import java.util.ArrayList;
import java.util.List;
//This class bundles methods/ data for a User object.
public class User {
private String userName;
private String userPassword;
private List<Playlist> userPlaylist;
/*
* Constructs a new instance of the User class with the
* specified name and password.
*/
public User(String name, String password) {
userName = name;
userPassword = password;
userPlaylist = new ArrayList<Playlist>();
}
//Returns the name of the user.
public String getName() {
return userName;
}
/*
* Returns true if the password is valid for this user.
* False otherwise.
*/
public boolean attemptLogin(String password) {
if (password.equals(userPassword)) {
return true;
}
return false;
}
//Adds the specified playlist to the user's playlists.
public void addPlaylist(Playlist newPlaylist) {
userPlaylist.add(newPlaylist);
}
//Returns a list of the playlists for this user.
public List<Playlist> getPlaylists() {
return userPlaylist;
}
/*
* Selects the playlist with the specified name if the
* user has a playlist by that name and plays the newly
* selected playlist.
*/
public void selectPlaylist(String name) {
for (int i = 0; i < userPlaylist.size(); i++) {
if (userPlaylist.get(i).getName().equals(name)) {
userPlaylist.get(i).play();
break;
}
}
}
/*
* Returns a string description of the user. The format
* is name, numPlaylists playlist. So if I had a user
* cjenkins who had 12 playlists this method would return
* "cjenkins, 12 playlists".
*/
public String toString() {
return userName + ", " + userPlaylist.size() + " playlists";
}
}