aboutsummaryrefslogtreecommitdiff
path: root/src/musichub/main/Main.java
blob: f917b01569d6e83a6711948b88082ec70c702eb7 (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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package musichub.main;

import musichub.business.*;

import java.util.Iterator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        MusicHub theHub = new MusicHub();

        System.out.println("Type h for available commands");


        Scanner scan = new Scanner(System.in);
        String choice = scan.nextLine();

        String albumTitle;

        if (choice.length() == 0) System.exit(0);

        while (choice.charAt(0) != 'q') {
            switch (choice.charAt(0)) {
                case 'h':
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 't':
                    //album titles, ordered by date
                    System.out.println(theHub.getAlbumsTitlesSortedByDate());
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'g':
                    //songs of an album, sorted by genre
                    System.out.println("Songs of an album sorted by genre will be displayed; enter the album name, available albums are:");
                    System.out.println(theHub.getAlbumsTitlesSortedByDate());

                    albumTitle = scan.nextLine();
                    try {
                        System.out.println(theHub.getAlbumSongsSortedByGenre(albumTitle));
                    } catch (NoAlbumFoundException ex) {
                        System.out.println("No album found with the requested title " + ex.getMessage());
                    }
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'd':
                    //songs of an album
                    System.out.println("Songs of an album will be displayed; enter the album name, available albums are:");
                    System.out.println(theHub.getAlbumsTitlesSortedByDate());

                    albumTitle = scan.nextLine();
                    try {
                        System.out.println(theHub.getAlbumSongs(albumTitle));
                    } catch (NoAlbumFoundException ex) {
                        System.out.println("No album found with the requested title " + ex.getMessage());
                    }
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'u':
                    //audiobooks ordered by author
                    System.out.println(theHub.getAudiobooksTitlesSortedByAuthor());
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'c':
                    // add a new song
                    System.out.println("Enter a new song: ");
                    System.out.println("Song title: ");
                    String title = scan.nextLine();
                    System.out.println("Song genre (jazz, classic, hiphop, rock, pop, rap):");
                    String genre = scan.nextLine();
                    System.out.println("Song artist: ");
                    String artist = scan.nextLine();
                    System.out.println("Song length in seconds: ");
                    int length = Integer.parseInt(scan.nextLine());
                    System.out.println("Song content: ");
                    String content = scan.nextLine();
                    Song s = new Song(title, artist, length, content, genre);
                    theHub.addElement(s);
                    System.out.println("New element list: ");
                    Iterator<AudioElement> it = theHub.elements();
                    while (it.hasNext()) System.out.println(it.next().getTitle());
                    System.out.println("Song created!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'a':
                    // add a new album
                    System.out.println("Enter a new album: ");
                    System.out.println("Album title: ");
                    String aTitle = scan.nextLine();
                    System.out.println("Album artist: ");
                    String aArtist = scan.nextLine();
                    System.out.println("Album length in seconds: ");
                    int aLength = Integer.parseInt(scan.nextLine());
                    System.out.println("Album date as YYYY-DD-MM: ");
                    String aDate = scan.nextLine();
                    Album a = new Album(aTitle, aArtist, aLength, aDate);
                    theHub.addAlbum(a);
                    System.out.println("New list of albums: ");
                    Iterator<Album> ita = theHub.albums();
                    while (ita.hasNext()) System.out.println(ita.next().getTitle());
                    System.out.println("Album created!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case '+':
                    //add a song to an album:
                    System.out.println("Add an existing song to an existing album");
                    System.out.println("Type the name of the song you wish to add. Available songs: ");
                    Iterator<AudioElement> itae = theHub.elements();
                    while (itae.hasNext()) {
                        AudioElement ae = itae.next();
                        if (ae instanceof Song) System.out.println(ae.getTitle());
                    }
                    String songTitle = scan.nextLine();

                    System.out.println("Type the name of the album you wish to enrich. Available albums: ");
                    Iterator<Album> ait = theHub.albums();
                    while (ait.hasNext()) {
                        Album al = ait.next();
                        System.out.println(al.getTitle());
                    }
                    String titleAlbum = scan.nextLine();
                    try {
                        theHub.addElementToAlbum(songTitle, titleAlbum);
                    } catch (NoAlbumFoundException | NoElementFoundException ex) {
                        System.out.println(ex.getMessage());
                    }
                    System.out.println("Song added to the album!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'l':
                    // add a new audiobook
                    System.out.println("Enter a new audiobook: ");
                    System.out.println("AudioBook title: ");
                    String bTitle = scan.nextLine();
                    System.out.println("AudioBook category (youth, novel, theater, documentary, speech)");
                    String bCategory = scan.nextLine();
                    System.out.println("AudioBook artist: ");
                    String bArtist = scan.nextLine();
                    System.out.println("AudioBook length in seconds: ");
                    int bLength = Integer.parseInt(scan.nextLine());
                    System.out.println("AudioBook content: ");
                    String bContent = scan.nextLine();
                    System.out.println("AudioBook language (french, english, italian, spanish, german)");
                    String bLanguage = scan.nextLine();
                    AudioBook b = new AudioBook(bTitle, bArtist, bLength, bContent, bLanguage, bCategory);
                    theHub.addElement(b);
                    System.out.println("Audiobook created! New element list: ");
                    Iterator<AudioElement> itl = theHub.elements();
                    while (itl.hasNext()) System.out.println(itl.next().getTitle());
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 'p':
                    //create a new playlist from existing elements
                    System.out.println("Add an existing song or audiobook to a new playlist");
                    System.out.println("Existing playlists:");
                    Iterator<PlayList> itpl = theHub.playlists();
                    while (itpl.hasNext()) {
                        PlayList pl = itpl.next();
                        System.out.println(pl.getTitle());
                    }
                    System.out.println("Type the name of the playlist you wish to create:");
                    String playListTitle = scan.nextLine();
                    PlayList pl = new PlayList(playListTitle);
                    theHub.addPlaylist(pl);
                    System.out.println("Available elements: ");

                    Iterator<AudioElement> itael = theHub.elements();
                    while (itael.hasNext()) {
                        AudioElement ae = itael.next();
                        System.out.println(ae.getTitle());
                    }
                    while (choice.charAt(0) != 'n') {
                        System.out.println("Type the name of the audio element you wish to add or 'n' to exit:");
                        String elementTitle = scan.nextLine();
                        try {
                            theHub.addElementToPlayList(elementTitle, playListTitle);
                        } catch (NoPlayListFoundException | NoElementFoundException ex) {
                            System.out.println(ex.getMessage());
                        }

                        System.out.println("Type y to add a new one, n to end");
                        choice = scan.nextLine();
                    }
                    System.out.println("Playlist created!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case '-':
                    //delete a playlist
                    System.out.println("Delete an existing playlist. Available playlists:");
                    Iterator<PlayList> itp = theHub.playlists();
                    while (itp.hasNext()) {
                        PlayList p = itp.next();
                        System.out.println(p.getTitle());
                    }
                    String plTitle = scan.nextLine();
                    try {
                        theHub.deletePlayList(plTitle);
                    } catch (NoPlayListFoundException ex) {
                        System.out.println(ex.getMessage());
                    }
                    System.out.println("Playlist deleted!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                case 's':
                    //save elements, albums, playlists
                    theHub.saveElements();
                    theHub.saveAlbums();
                    theHub.savePlayLists();
                    System.out.println("Elements, albums and playlists saved!");
                    printAvailableCommands();
                    choice = scan.nextLine();
                    break;
                default:

                    break;
            }
        }
        scan.close();
    }

    private static void printAvailableCommands() {
        System.out.println("t: display the album titles, ordered by date");
        System.out.println("g: display songs of an album, ordered by genre");
        System.out.println("d: display songs of an album");
        System.out.println("u: display audiobooks ordered by author");
        System.out.println("c: add a new song");
        System.out.println("a: add a new album");
        System.out.println("+: add a song to an album");
        System.out.println("l: add a new audiobook");
        System.out.println("p: create a new playlist from existing songs and audio books");
        System.out.println("-: delete an existing playlist");
        System.out.println("s: save elements, albums, playlists");
        System.out.println("q: quit program");
    }
}