-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.java
109 lines (96 loc) · 3.2 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.util.Date;
public class User extends StructUser {
private MusicCollection myMusics;
public User(String name, String login, String password) {
super(name, login, password);
this.myMusics = new MusicCollection();
}
public String toString() {
return "Name: " + this.getName() + "\nLogin: " + this.getLogin() + "\nPassword: " + this.getPassword();
}
public MusicCollection getMyMusics() {
return myMusics;
}
// User is restricted to myMusics and cannot modify allMusics
public void addMusic(MusicCollection allMusics, StructMusic music) {
boolean musicExists = false;
for (StructMusic m : allMusics.getAllMusics()) {
if (m.getTitle().equals(music.getTitle())) {
musicExists = true;
break;
}
}
if (musicExists == false) { // add from main collection
allMusics.getAllMusics().add(music);
allMusics.incrementMusics();
myMusics.getAllMusics().add(music);
myMusics.incrementMusics();
System.out.println("Music added!");
}
}
public StructMusic searchMusic(String title) {
for (StructMusic m : myMusics.getAllMusics()) {
if (m.getTitle().equals(title)) {
return m;
}
}
return null;
}
public StructMusic searchMusic(int id) {
for (StructMusic m : myMusics.getAllMusics()) {
if (m.getId() == id) {
m.toString();
}
}
return null;
}
public StructMusic removeMusic(int id) {
for (StructMusic m : myMusics.getAllMusics()) {
if (m.getId() == id) {
myMusics.getAllMusics().remove(m);
myMusics.decrementMusics();
System.out.println("Music removed!");
return m;
}
}
return null;
}
public StructMusic removeMusic(String title) {
for (StructMusic m : myMusics.getAllMusics()) {
if (m.getTitle() == title) {
myMusics.getAllMusics().remove(m);
myMusics.decrementMusics();
System.out.println("Music removed!");
return m;
}
}
return null;
}
public void updateMusic(int id, String title, Duration duration, String authors,
Date date, String genre) {
StructMusic m = searchMusic(id);
if (m != null) {
m.setTitle(title);
m.setDuration(duration);
m.setAuthors(authors);
m.setDate(date);
m.setGenre(genre);
System.out.println("Music updated!");
}
}
public void updateMusic(String oldTitle, String newTitle, Duration duration, String authors,
Date date, String genre) {
StructMusic m = searchMusic(oldTitle);
if (m != null) {
m.setTitle(newTitle);
m.setDuration(duration);
m.setAuthors(authors);
m.setDate(date);
m.setGenre(genre);
System.out.println("Music updated!");
}
}
public void printMusics() {
myMusics.printMusics();
}
}