blob: ecbb1eb66b9c0a2bc39f1ef168244a27adc93d54 (
plain)
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
|
public class Song extends MusicalElement{
private String artist, genre;
public Song(String title, int duration, String content, String artist, Genre genre) {
super(title, duration, content);
this.artist=artist;
this.genre=genre.name();
}
public String getArtist(){return artist;}
public String getGenre(){return genre;}
public void setArtist(String artist){this.artist=artist;}
public void setGenre(Genre genre){this.genre=genre.name();}
public String toString() {
return getTitle()+";"+getDuration()+";"+getContent()+";"+artist+";"+genre;
}
public void save(){
try
{
//Saving of object in a file
FileOutputStream file = new FileOutputStream(songs.csv);
ObjectOutputStream out = new ObjectOutputStream(file);
// Method for serialization of object
out.writeObject(this);
out.close();
file.close();
System.out.println("Object has been serialized");
}
catch(IOException ex)
{
System.out.println("IOException is caught");
}
}
}
|