Java项⽬实战---歌曲管理系统Java项⽬实战—歌曲管理系统
声明:本⼈仅整理了代码,⽅便⼤家进⾏调试优化,功能上还存在很多纰漏,欢迎⼤家评论区讨论代码原地址放于⽂章末尾
⼀、实验⽬的:
掌握类的定义,JAVA应⽤程序的设计与实现。
⼆、实验内容:
开发环境
Eclipse + JDK + List/Map + File
系统中的对象
歌曲(Song.java):编号、歌名、语⾔(中⽂/英⽂)、类别(流⾏/通俗)、歌⼿
系统功能描述
对已有的曲⽬进⾏管理:
查歌曲信息(按歌名\语⾔\歌⼿\类别等进⾏查询)
增加歌曲
删除某歌曲
技术要求
List/Map,File, 输⼊输出流对象
画⾯参考
三、实验要求:
1. 通过实验掌握⽂件输⼊输出流的使⽤⽅法;
2. 程序必须能够从键盘接收字符串并保存在⽂件中;
3. 程序必须能够读出⽂件内容显⽰在屏幕上;
4. 数据保存在⽂件中;
四、实验步骤:
1. 分析需求,设计类并画出类框图;
2. 实现类,完成相应功能
3. 调试运⾏程序。
代码展⽰
以下为 Song.java 部分代码
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
public class Song {
private int sid;
private String sname;
private String category;
private String singer;
public Song(){
}
public Song(int sid, String sname, String category, String singer){ super();
this.sid = sid;
this.sname = sname;
this.category = category;
this.singer = singer;
}
public int getSid(){
return sid;
}
public void setSid(int sid){
this.sid = sid;
}
public String getSname(){
return sname;
}
public void setSname(String sname){
this.sname = sname;
}
public String getCategory(){
return category;
}
public void setCategory(String category){
this.category = category;
}
public String getSinger(){
return singer;
}
public void setSinger(String singer){
this.singer = singer;
}
}
以下为 SongDao.java 部分的代码
private List<Song> songList;
王弢个人资料public SongDao(){
}
public SongDao(List<Song> songList){
郝蕾个人资料super();
this.songList = songList;
}
//    新增歌曲
public void add(Song song){
秦时明月电视剧主题曲songList.add(song);
}
//    查询歌曲
/
/    按id查
public Song search(int sid){
for(Song song : songList){
Sid()== sid){
return song;
}
}
return null;
}//    按对象查
public Song search(Song song){
if(song == null){
return null;
}
return Sid());
}
//    删除歌曲
//按id删除歌曲
public void delete(int sid){
Song song =search(sid);
if(song != null){
}
}
//按对象删除歌曲
public void delete(Song song){
if(song != null){
Sid());
}
}
public List<Song>getSongList(){
return songList;
}
public void setSongList(List<Song> songList){
this.songList = songList;
}
}
以下为 SongService.java 部分的代码
private SongDao dao;
public SongService(){
super();
// TODO Auto-generated constructor stub
}
public SongService(SongDao dao){
super();
this.dao = dao;
}
public void add(Song song){
dao.add(song);
}
public Song search(int sid){
return dao.search(sid);
}
public Song search(Song song){
return dao.search(song);
}
public void delete(Song song){
dao.delete(song);
郑国霖女友}
public void delete(int id){
dao.delete(id);
}
public List<Song>trace(){
SongList();
}
public void alter(Song song){
}
public SongDao getDao(){
return dao;
}
public void setDao(SongDao dao){
this.dao = dao;
}
}
以下为 SongView.java 部分的代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.DatagramPacket;
import java.util.ArrayList;
import java.util.List;
import AbstractDocument.BranchElement; public class SongView {
private SongService service;
public SongView(){
super();
//TODO Auto-generated constructor stub
}
public SongView(SongService service){
super();
this.service = service;
}
public void show()throws Exception {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
boolean stop =false;
while(!stop){
System.out.println("****************************************************\n"不可以喜欢你
+"                                      **歌曲管理** \n"
+"    1-----------------------------------查歌曲\n"
+"    2-----------------------------------增加歌曲\n"
+"    3-----------------------------------删除歌曲\n"
+"    4-----------------------------------显⽰所有歌曲\n"
新水浒背景音乐
+"    5-----------------------------------退出系统\n"
+"****************************************************\n"
+"                                      **input [1-5]:");
String line = br.readLine();
int command = Integer.parseInt(line);
switch(command){
case1:
System.out.println("Sccording to id or complete info?Input[lor2]");
line = br.readLine();
command = Integer.parseInt(line);
if(command ==2){
System.out.println("Input song's id");
String sid = br.readLine();
int id = Integer.parseInt(sid);
System.out.println("Input song's name:");
String sname = br.readLine();
System.out.println("Input singer's name");
String singerName = br.readLine();
System.out.println("Input song's category");
String category = br.readLine();
Song song =new Song(id, sname, category, singerName);
print(service.search(song));
}else{
System.out.println("Input song's id");
String sid = br.readLine();
int id = Integer.parseInt(sid);
print(service.search(id));
}
break;
case2:
System.out.println("Input new song's id");
String sid = br.readLine();
int id = Integer.parseInt(sid);
System.out.println("Input new song's name");
String sname = br.readLine();
System.out.println("Input new singer's name");
String singerName = br.readLine();
System.out.println("Input song's category");
String category = br.readLine();
Song song =new Song(id, sname, category, singerName);
service.add(song);
break;