练习打卡,麻烦老师检查~

练习打卡,麻烦老师检查~

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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
package com.imooc.player;
 
import java.util.Scanner;
 
public class TestDemo {
 
    // 对歌曲Song类进行测试
    public void testSong() {
        Song song1 = new Song("s001""两只老虎""小太阳");
        Song song2 = new Song("s002""小燕子""风车");
        Song song3 = new Song("s003""茉莉花""彩虹");
        Song song4 = new Song("s003""茉莉花""彩虹");
        System.out.println(song1);
        // 测试song1和song3这两个对象是否相等
        System.out.println("song1==song3?" + song1.equals(song3));
        System.out.println("song1==song3?" + song4.equals(song3));
    }
 
    // 对播放列表类PlayList进行测试
    public void testPlayList() {
        // 定义几个Song类对象,添加到播放列表当中
        Song song1 = new Song("s001""两只老虎""小太阳");
        Song song2 = new Song("s002""小燕子""风车");
        Song song3 = new Song("s003""茉莉花""彩虹");
//      Song song4 = new Song("s003", "茉莉花", "彩虹");  
        // 创建一个PlayList对象
        PlayList mainPlayList = new PlayList("");
        mainPlayList.addToPlayList(song1);
        mainPlayList.addToPlayList(song2);
        mainPlayList.addToPlayList(song3);
//      mainPlayList.addToPlayList(song4);
        // 显示播放列表内容
        mainPlayList.displayAllSong();
        // 通过id查询歌曲信息
        Song song = mainPlayList.searchSongById("s005");
        if (song != null) {
            System.out.println("通过id查询歌曲信息:");
            System.out.println(song);
        else {
            System.out.println("该歌曲不存在!");
        }
        //
        song = null;
        song = mainPlayList.searchSongByName("小燕子");
        if (song != null) {
            System.out.println("通过name查询歌曲信息:");
            System.out.println(song);
        else {
            System.out.println("该歌曲不存在!");
        }
        // 修改歌曲信息
        Song songUpdate = new Song("s005""蜗牛与黄鹂鸟""小太阳");
        mainPlayList.updatedSong("s003", songUpdate);
        mainPlayList.displayAllSong();
        // 删除歌曲信息
        mainPlayList.deleteSong("s005");
        mainPlayList.displayAllSong();
    }
 
    // 测试播放列表集合类
    public void testPlayListCollection() {
        Song song1 = new Song("s001""两只老虎""小太阳");
        Song song2 = new Song("s002""小燕子""风车");
        Song song3 = new Song("s003""茉莉花""彩虹");
        // 创建主播放列表
        PlayList mainPlayList = new PlayList("主播放列表");
        // 将歌曲添加到主播放列表中
        mainPlayList.addToPlayList(song1);
        mainPlayList.addToPlayList(song2);
        mainPlayList.addToPlayList(song3);
        // 定义一个新的播放列表,从主播放列表中添加歌曲进来
        PlayList favouritePlayList = new PlayList("最喜欢的歌曲");
        favouritePlayList.addToPlayList(mainPlayList.getMusicList().get(0));
        favouritePlayList.addToPlayList(mainPlayList.getMusicList().get(1));
        favouritePlayList.displayAllSong();
        // 将两个播放列表添加到播放列表集合中(播放器)
        PlayListCollection plc = new PlayListCollection();
        plc.addPlayList(mainPlayList);
        plc.addPlayList(favouritePlayList);
        plc.displayPlayListName();
        // 根据播放列表名字查询播放列表信息,并显示所有歌曲
        PlayList playList = plc.searchPlayListByName("最喜欢的歌曲");
        playList.displayAllSong();
        // 删除播放列表信息
        System.out.println("删除前:");
        plc.displayPlayListName();
        plc.deletePlayList(favouritePlayList);
        System.out.println("删除后:");
        plc.displayPlayListName();
    }
 
    // 主菜单
    public void mainMenu() {
        System.out.println("*************************************");
        System.out.println("              **主菜单***             ");
        System.out.println("              1--播放列表管理          ");
        System.out.println("              2--播放器管理            ");
        System.out.println("              0--退出                 ");
        System.out.println("*************************************");
    }
 
    // 播放列表管理菜单
    public void playListMenu() {
        System.out.println("*************************************");
        System.out.println("              **播放列表管理***             ");
        System.out.println("              1--将歌曲添加到主播放列表          ");
        System.out.println("              2--将歌曲添加到普通播放列表          ");
        System.out.println("              3--通过歌曲id查询播放列表中的歌曲          ");
        System.out.println("              4--通过歌曲名称查询播放列表中的歌曲          ");
        System.out.println("              5--修改播放列表中的歌曲          ");
        System.out.println("              6--删除播放列表中的歌曲         ");
        System.out.println("              7--显示播放列表中的所有歌曲          ");
        System.out.println("              9--返回上一级菜单          ");
        System.out.println("*************************************");
    }
 
    // 播放器管理菜单
    public void playerMenu() {
        System.out.println("*************************************");
        System.out.println("              **播放器管理***            ");
        System.out.println("              1--向播放器添加播放列表          ");
        System.out.println("              2--从播放器删除播放列表          ");
        System.out.println("              3--通过名称查询播放列表          ");
        System.out.println("              4--显示所有播放列表名称          ");
        System.out.println("              9--返回上一级菜单          ");
        System.out.println("*************************************");
    }
 
    // 主流程
    public void test() {
        TestDemo td = new TestDemo();
        Scanner sc = new Scanner(System.in);
        int input = 0;
        int input1 = 0;
        int input2 = 0;
        // 创建一个播放列表容器(播放器)
        PlayListCollection plc = new PlayListCollection();
        // 创建主播放列表
        PlayList mainPlayList = new PlayList("主播放列表");
        // 将主播放列表添加到播放器
        plc.addPlayList(mainPlayList);
        PlayList favouritePlayList = null;
        while (true) {
            td.mainMenu();
            System.out.println("请输入相应的数字进行操作:");
            input = sc.nextInt();
            if (input == 0) {
                break;
            }
            switch (input) {
            case 1:
                // 播放列表管理
                while (true) {
                    td.playListMenu();
                    System.out.println("请输入相应的数字对播放列表进行管理:");
                    input1 = sc.nextInt();
                    if (input1 == 9) {
                        break;
                    }
                    switch (input1) {
                    case 1:
                        System.out.println("将歌曲添加到主播放列表");
                        System.out.println("请输入要添加的歌曲的数量:");
                        int count = sc.nextInt();
                        for (int i = 1; i <= count; i++) {
                            System.out.println("请输入第" + i + "首歌曲:");
                            System.out.println("请输入歌曲id:");
                            String strId = sc.next();
                            System.out.println("请输入歌曲名称:");
                            String strName = sc.next();
                            System.out.println("请输入歌曲演唱者:");
                            String strSinger = sc.next();
                            //// 创建歌曲类的对象
                            Song song = new Song(strId, strName, strSinger);
                            mainPlayList.addToPlayList(song);
//                          mainPlayList.displayAllSong();
                        }
                        break;
                    case 2:
                        System.out.println("将歌曲添加到普通播放列表");
                        System.out.println("请输入要添加的播放列表名称:");
                        String sName = sc.next();
                        // 根据名称判断播放列表是否存在在播放器中
                        favouritePlayList = plc.searchPlayListByName(sName);
                        if (favouritePlayList == null) {
                            System.out.println("该播放列表不存在,请先将播放列表添加到播放器中!");
                        else {
                            System.out.println("请输入要添加的歌曲的数量:");
                            int count1 = sc.nextInt();
                            for (int i = 1; i <= count1; i++) {
                                System.out.println("请输入第" + i + "首歌曲:");
                                System.out.println("请输入歌曲id:");
                                String strId = sc.next();
                                // 首先判断该id的歌曲是否存在于主播放列表存在
                                Song song = mainPlayList.searchSongById(strId);
                                if (song == null) {
                                    // 如果歌曲不存在,则创建新的添加,并且添加到主播放列表
                                    System.out.println("该歌曲在主播放列表不存在,继续输入歌曲的其他信息");
                                    System.out.println("请输入歌曲名称:");
                                    String strName = sc.next();
                                    System.out.println("请输入歌曲演唱者:");
                                    String strSinger = sc.next();
                                    // 创建一个Song类对象
                                    song = new Song(strId, strName, strSinger);
                                    // 分别将歌曲添加到普通播放列表和主播放列表中
                                    favouritePlayList.addToPlayList(song);
                                    mainPlayList.addToPlayList(song);
                                else {
                                    // 如果歌曲存在于主播放列表,则直接添加到现在的播放列表
                                    favouritePlayList.addToPlayList(song);
                                }
                            }
                            // 显示播放列表中的歌曲信息
                            System.out.println("主播放列表");
                            mainPlayList.displayAllSong();
                            System.out.println("普通播放列表");
                            favouritePlayList.displayAllSong();
                        }
                        break;
                    case 3:
                        System.out.println("通过歌曲id查询播放列表中的歌曲");
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayListName1 = sc.next();
                        // 查询播放列表是否存在
                        PlayList pl1 = plc.searchPlayListByName(strPlayListName1);
                        if (pl1 == null) {
                            System.out.println("该播放列表不存在!");
                            break;
                        else {
                            System.out.println("请输入要查询的歌曲id:");
                            String strId1 = sc.next();
                            Song s = pl1.searchSongById(strId1);
                            if (s == null) {
                                System.out.println("该歌曲在播放列表" + strPlayListName1 + "中不存在!");
                            else {
                                System.out.println("该歌曲的信息为:");
                                System.out.println(s);
                            }
                        }
                        break;
                    case 4:
                        System.out.println("通过歌曲名称查询播放列表中的歌曲");
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayListName2 = sc.next();
                        PlayList pl2 = plc.searchPlayListByName(strPlayListName2);
                        if (pl2 == null) {
                            System.out.println("该播放列表不存在!");
                            break;
                        else {
                            System.out.println("请输入要查询的歌曲name:");
                            String strName1 = sc.next();
                            Song s = pl2.searchSongByName(strName1);
                            if (s == null) {
                                System.out.println("该歌曲不存在!");
                            else {
                                System.out.println("该歌曲的信息为:");
                                System.out.println(s);
                            }
                        }
                        break;
                    case 5// 通过id改演唱者和名称
                        System.out.println("修改播放列表中的歌曲");
                        System.out.println("请输入要修改的歌曲id:");
                        String strId = sc.next();
//                      // 首先判断该id的歌曲是否存在于主播放列表存在
                        Song song = mainPlayList.searchSongById(strId);
                        if (song == null) {
                            // 如果歌曲不存在
                            System.out.println("该歌曲在主播放列表不存在,请重新输入要修改的歌曲id");
                        else {
                            System.out.println("请输入新的歌曲名称:");
                            String strName = sc.next();
                            System.out.println("请输入新的歌曲演唱者:");
                            String strSinger = sc.next();
                            // 创建一个Song类对象
                            song = new Song(strId, strName, strSinger);
                            // 把更新的歌曲信息加入主播放列表
                            System.out.println("歌曲信息修改前的播放列表歌曲:");
                            mainPlayList.updatedSong(strId, song);
                            System.out.println("歌曲信息修改后的播放列表歌曲");
                            mainPlayList.displayAllSong();
                        }
                        break;
                    case 6:
                        System.out.println("删除播放列表中的歌曲");
                        System.out.println("请输入要修改的歌曲id:");
                        String strId1 = sc.next();
                        mainPlayList.deleteSong(strId1);
                        break;
                    case 7:
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayListName = sc.next();
                        // 查询播放列表是否存在
                        PlayList pl3 = plc.searchPlayListByName(strPlayListName);
                        if (pl3 == null) {
                            System.out.println("该播放列表不存在!");
                            break;
                        else {
                            if (pl3.equals(mainPlayList)) {
                                System.out.println("显示播放列表中的所有歌曲");
                                mainPlayList.displayAllSong();
                            else {
                                if (favouritePlayList != null) {
                                    System.out.println("显示播放列表中的所有歌曲");
                                    favouritePlayList.displayAllSong();
                                else {
                                    System.out.println("该列表尚未添加歌曲!");
                                }
 
                            }
                        }
                        break;
                    default:
                        System.out.println("该数字没有相应的操作!");
                        break;
                    }
                }
                break;
            case 2:
                // 播放器管理
                while (true) {
                    td.playerMenu();
                    System.out.println("请输入相应的数字对播放器进行管理:");
                    input2 = sc.nextInt();
                    if (input2 == 9) {
                        System.out.println("返回上级菜单");
                        break;
                    }
                    switch (input2) {
                    case 1:
                        System.out.println("向播放器添加播放列表");
                        System.out.println("输入要添加的播放列表名称:");
                        String playerName = sc.next();
                        // 创建一个新的播放列表对象
                        favouritePlayList = new PlayList(playerName);
                        // 将播放列表添加到播放器Map
                        plc.addPlayList(favouritePlayList);
                        break;
                    case 2:
                        System.out.println("从播放器删除播放列表");
                        System.out.println("请输入要删除的播放列表名称:");
                        String strPlayListName = sc.next();
                        if (strPlayListName.equals("主播放列表")) {
                            System.out.println("主播放列表不能删除!");
                            break;
                        }
                        // 查询播放列表是否存在
                        PlayList playList1 = plc.searchPlayListByName(strPlayListName);
                        if (playList1 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            // 存在则删除
                            plc.deletePlayList(playList1);
                        }
                        break;
                    case 3:
                        System.out.println("通过名字查询播放列表");
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayList1 = sc.next();
                        PlayList playList2 = plc.searchPlayListByName(strPlayList1);
                        if (playList2 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            // 显示该播放列表名称及其中的所有歌曲
                            System.out.println("该播放列表存在!");
                            System.out.println("该播放列表的名称为:" + strPlayList1);
                            playList2.displayAllSong();
                        }
                        break;
                    case 4:
                        System.out.println("显示所有播放列表名称");
                        plc.displayPlayListName();
                        break;
 
                    default:
                        System.out.println("该数字没有相应的操作!");
                        break;
                    }
                }
            default:
                System.out.println("该数字没有相应的操作!");
            }
        }
 
    }
 
    public static void main(String[] args) {
        TestDemo td = new TestDemo();
//      td.testSong();
//      td.testPlayList();
//      td.testPlayListCollection();
        td.test();
    }
 
}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
wangstudyvc 2020-07-05 11:56:28
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package com.imooc.player;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
 
public class TestDemo {
 
 
    // 主菜单
    public void mainMenu() {
        System.out.println("***************************************");
        System.out.println("                 **主菜单**                      ");
        System.out.println("                 1--播放列表管理    ");
        System.out.println("                 2--播放器管理    ");
        System.out.println("                 0--退出   ");
        System.out.println("***************************************");
 
    }
 
    // 播放列表管理菜单
    public void playListMenu() {
        System.out.println("*******************************************************");
        System.out.println("                 **播放列表管理**    ");
        System.out.println("                 1--将歌曲添加到主播放列表    ");
        System.out.println("                 2--将歌曲添加到普通播放列表    ");
        System.out.println("                 3--通过歌曲id查询播放列表中的歌曲    ");
        System.out.println("                 4--通过歌曲名称查询播放列表中的歌曲    ");
        System.out.println("                 5--修改播放列表中的歌曲    ");
        System.out.println("                 6--删除播放列表中的歌曲    ");
        System.out.println("                 7--显示播放列表中的所有歌曲    ");
        System.out.println("                 8--导出歌单    ");
        System.out.println("                 9--返回上一级菜单   ");
        System.out.println("*******************************************************");
    }
 
    // 播放器菜单
    public void playerMenu() {
        System.out.println("*******************************************************");
        System.out.println("                 **播放器管理**    ");
        System.out.println("                 1--向播放器添加播放列表    ");
        System.out.println("                 2--从播放器删除播放列表    ");
        System.out.println("                 3--通过名字查询播放列表信息    ");
        System.out.println("                 4--显示所有播放列表名称    ");
        System.out.println("                 9--返回上一级菜单   ");
        System.out.println("*******************************************************");
    }
 
    // 主流程
    public void test() {
        TestDemo td = new TestDemo();
        Scanner sc = new Scanner(System.in);
        int input = 0, input1 = 0, input2 = 0;
        // 创建一个播放列表容器(播放器)
        PlayListCollection plc = new PlayListCollection();
        // 创建主播放列表
        PlayList mainPlayList = new PlayList("主播放列表");
        // 将主播放列表添加到播放器
        plc.addPlayList(mainPlayList);
        PlayList favouritePlayList = null;
        while (true) {
            td.mainMenu();
            System.out.println("请输入对应数字进行操作:");
            input = sc.nextInt();
            if (input == 0) {
                break;
            }
            switch (input) {
             
                    case 4:
                        System.out.println("通过歌曲名称查询播放列表中的歌曲");
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayListName2 = sc.next();
                        // 查询播放列表是否存在
                        PlayList p2 = plc.searchPlayListByName(strPlayListName2);
                        if (p2 == null) {
                            System.out.println("该播放列表不存在!");
                            break;
                        else {
                            System.out.println("请输入要查询的歌曲名称:");
                            String strName2 = sc.next();
                            Song s2 = p2.searchSongByName(strName2);
                            if (s2 == null) {
                                System.out.println("该歌曲在播放列表" + strPlayListName2 + "中不存在!");
                            else {
                                System.out.println("该歌曲的信息为:");
                                System.out.println(s2);
                            }
                        }
                        break;
                    case 5:
                        System.out.println("修改播放列表中的歌曲");
                        System.out.println("请输入要修改歌曲的播放列表名称:");
                        String strPlayListName3 = sc.next();
                        PlayList p3 = plc.searchPlayListByName(strPlayListName3);
                        if (p3 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            System.out.println("请输入要修改的歌曲ID:");
                            String strId3 = sc.next();
                            // 是否在给定的播放列表中存在此歌曲
                            if (p3.searchSongById(strId3) != null) {
                                System.out.println("请输入歌曲名称:");
                                String strName3 = sc.next();
                                System.out.println("请输入演唱者:");
                                String strSinger3 = sc.next();
                                // 创建一个Song类的对象
                                Song newSong = new Song(strId3, strName3, strSinger3);
                                p3.updateSong(strId3, newSong);
                                // 判断给定的播放列表是否为主播放列表
                                if ("主播放列表".equals(p3.getPlayListName())) {
                                    // 同步更新到其他播放列表
                                    Map<String, PlayList> playListMap = plc.getPlayListMap();
                                    Iterator<Entry<String, PlayList>> it = playListMap.entrySet().iterator();
                                    while (it.hasNext()) {
                                        Entry<String, PlayList> entry = it.next();
                                        if (!entry.getKey().equals("主播放列表")
                                                && null != entry.getValue().searchSongById(strId3)) {
                                            entry.getValue().updateSong(strId3, newSong);
                                        }
                                    }
                                else {
                                    // 同步更新主播放列表
                                    mainPlayList.updateSong(strId3, newSong);
                                }
                            else {
                                System.out.println("待修改的歌曲在该播放列表中不存在!");
                                break;
                            }
                        }
                        break;
                    case 6:
                        System.out.println("删除播放列表中的歌曲");
                        System.out.println("请输入要删除的歌曲ID:");
                        String strId6 = sc.next();
                        Map<String, PlayList> playListMap = plc.getPlayListMap();
                        Iterator<Entry<String, PlayList>> it = playListMap.entrySet().iterator();
                        while (it.hasNext()) {
                            Entry<String, PlayList> entry = it.next();
                            if (null != entry.getValue().searchSongById(strId6)) {
                                entry.getValue().deleteSong(strId6);
                            }
                        }
                        break;
                    case 7:
                        System.out.println("显示播放列表中的所有歌曲");
                        System.out.println("请输入要显示所有歌曲的播放列表名称:");
                        String strPlayListName7 = sc.next();
                        // 查询播放列表是否存在
                        PlayList p7 = plc.searchPlayListByName(strPlayListName7);
                        if (p7 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            p7.displayAllSong();
                        }
                        break;
                    case 8:
                        // 导出歌单信息
                        System.out.println("导出歌单");
                        System.out.println("请输入播放列表名称:");
                        String strPlayListName8 = sc.next();
                        PlayList p8 = plc.searchPlayListByName(strPlayListName8);
                        if (p8 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            System.out.println("请输入需要导出的歌曲名称:");
                            String songName = sc.next();
                            Song song = p8.searchSongByName(songName);
                            if (null != song) {
                                try {
                                    FileOutputStream fos = new FileOutputStream(songName + ".txt");
                                    ObjectOutputStream oos = new ObjectOutputStream(fos);
                                    oos.writeObject(song);
                                    oos.flush();
                                    oos.close();
                                    fos.close();
                                    // 从文件反序列表显示进行验证
                                    FileInputStream fis = new FileInputStream(songName + ".txt");
                                    ObjectInputStream ois = new ObjectInputStream(fis);
                                    Song song2 = (Song) ois.readObject();
                                    System.out.println("导出的歌曲信息为:" + song2);
                                    ois.close();
                                    fis.close();
                                catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                catch (ClassNotFoundException e) {
                                    e.printStackTrace();
                                catch (IOException e) {
                                    e.printStackTrace();
                                }
                            else {
                                System.out.println("歌曲" + songName + "在该播放列表中不存在!");
                            }
                        }
                        break;
                    default:
                        System.out.println("该歌曲没有对应的操作!");
                        break;
                    }
                }
                break;
            case 2:
                // 播放器管理
                while (true) {
                    td.playerMenu();
                    System.out.println("请输入对应的数字对播放器进行管理:");
                    input2 = sc.nextInt();
                    if (input2 == 9)
                        break;
                    switch (input2) {
                    case 1:
                        System.out.println("向播放器添加播放列表");
                        System.out.println("输入要添加的播放列表名称:");
                        String playerName = sc.next();
                        // 创建一个新的播放列表对象
                        favouritePlayList = new PlayList(playerName);
                        // 将播放列表添加到播放器Map
                        plc.addPlayList(favouritePlayList);
                        break;
                    case 2:
                        System.out.println("从播放器删除播放列表");
                        System.out.println("请输入要删除的播放列表名称:");
                        String strPlayListName = sc.next();
                        if (strPlayListName.equals("主播放列表")) {
                            System.out.println("主播放列表不能删除!");
                            break;
                        }
                        // 查询播放列表是否存在
                        PlayList playList1 = plc.searchPlayListByName(strPlayListName);
                        if (playList1 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            // 存在则删除
                            plc.deletePlayList(playList1);
                        }
                        break;
                    case 3:
                        System.out.println("通过名字查询播放列表信息");
                        System.out.println("请输入要查询的播放列表名称:");
                        String strPlayList1 = sc.next();
                        PlayList playList2 = plc.searchPlayListByName(strPlayList1);
                        if (playList2 == null) {
                            System.out.println("该播放列表不存在!");
                        else {
                            // 显示该播放列表名称及其中的所有歌曲
                            System.out.println("该播放列表存在!");
                            System.out.println("该播放列表的名称为:" + strPlayList1);
                            playList2.displayAllSong();
                        }
                        break;
                    case 4:
                        System.out.println("显示所有播放列表名称");
                        plc.displayListName();
                        break;
                    default:
                        System.out.println("该歌曲没有对应的操作!");
                        break;
 
                    }
                }
                break;
            default:
                System.out.println("该歌曲没有对应的操作!");
                break;
            }
        }
    }
 
 
}


好帮手慕阿慧 2020-06-23 11:02:39

同学你好,同学已完成练习,棒棒哒!继续加油!如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 此同学的练习都没有做完,序列号的附加题都没哟做,怎么就完成了呢:( 另外,修改和删除的功能,此段代码都没有考虑普通播放列表的情况,还是有疏漏的。 附上我的代码,供参考和老师检查正确性及代码规范
    2020-07-05 11:53:16
  • 同学的考虑的很完整,代码完成的也很棒。继续加油。祝:学习愉快~
    2020-07-05 16:18:36
  • 想问问为什么每次导出时都会有报错语句!但看了看根目录也有导出歌单啊!
    2020-07-15 19:37:47
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码