java歌_java歌曲管理系统

1 packageex8;2

3 importjava.io.BufferedReader;4 importjava.io.InputStreamReader;5 importjava.net.DatagramPacket;6 importjava.util.ArrayList;7 importjava.util.List;8 importjavax.swing.text.AbstractDocument.BranchElement;9

10 public classSongView {11

12 privateSongService service;13

14 publicSongView() {15 super();16 //TODO Auto-generated constructor stub

17 }18

19 publicSongView(SongService service) {20 super();21 this.service =service;22 }23

24 public void show() throwsException{25 BufferedReader br=new BufferedReader(newInputStreamReader(System.in));26 boolean stop=false;27 while(!stop){28 System.out.println("****************************************************\n"

29 +" **歌曲管理** \n"

30 +" 1-----------------------------------查找歌曲\n"

31 +" 2-----------------------------------增加歌曲\n"

32 +" 3-----------------------------------删除歌曲\n"

33 +" 4-----------------------------------显示所有歌曲\n"

34 +" 5-----------------------------------退出系统\n"

35 +"****************************************************\n"

36 +" **input [1-5]:");37 String line =br.readLine();38 int command=Integer.parseInt(line);39 switch(command) {40 case 1:41 System.out.println("According to id or complete info?Input[1or2]");42 line =br.readLine();43 command=Integer.parseInt(line);44 if(command==2) {45 System.out.println("Input song's id");46 String sid=br.readLine();47 int id=Integer.parseInt(sid);48 System.out.println("Input song's name");49 String sname=br.readLine();50 System.out.println("Input singer's name");51 String singerName=br.readLine();52 System.out.println("Input song's category");53 String category=br.readLine();54 Song song=newSong(id,sname,category,singerName);55 print(service.search(song));56 }57 else{58 System.out.println("Input song's id");59 String sid=br.readLine();60 int id=Integer.parseInt(sid);61 print(service.search(id));62 }63 break;64 case 2:65 System.out.println("Input new song's id");66 String sid=br.readLine();67 int id=Integer.parseInt(sid);68 System.out.println("Input new song's name");69 String sname=br.readLine();70 System.out.println("Input new singer's name");71 String singerName=br.readLine();72 System.out.println("Input song's category");73 String category=br.readLine();74 Song song=newSong(id,sname,category,singerName);75 service.add(song);76 break;77 case 3:78 System.out.println("请输入待删除歌曲的编号");79 sid=br.readLine();80 id=Integer.parseInt(sid);81 service.delete(id);82 System.out.println("Delete seccessfully");83 break;84 case 4:85 Listlist=service.trace();86 print(list);87 break;88 case 5:89 stop=true;90 System.out.println("Byebye");91 break;92 default:93 System.out.println("Error in input,try again");94 break;95 }96 }97 }98

99

100

101

102

103

104 public voidprint(Song song) {105 System.out.printf("%-10s%-15s%-15s%-15s\n","ID","NAME","SINGER","CATEGORY");106 System.out.println("----------------------------------------------------------------------");107 System.out.printf("%-15d%-20s%-25s%-20s\n",108 song.getSid(),song.getSname(),song.getSinger(),song.getCategory());109 }110

111 public void print(Listlist) {112 System.out.printf("%-10s%-15s%-15s%-15s\n","ID","NAME","SINGER","CATEGORY");113 System.out.println("----------------------------------------------------------------------");114 for(Song song: list)115 System.out.printf("%-15d%-20s%-25s%-20s\n",116 song.getSid(),song.getSname(),song.getSinger(),song.getCategory());117 }118

119 public static voidmain(String[] args) {120 SongView view=newSongView();121 SongService service=newSongService();122 SongDao dao=newSongDao();123 Listlist=new ArrayList<>();124 dao.setSongList(list);125 service.setDao(dao);126 view.setSongService(service);127 try{128 view.show();129 } catch(Exception e) {130 //TODO: handle exception

131 System.out.println(e);132 }133 }134

135 publicSongService getSongService() {136 returnservice;137 }138

139 public voidsetSongService(SongService songService) {140 this.service =songService;141 }142

143 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值