您好,欢迎访问三七文档
packageutil;importjava.io.FileOutputStream;importjava.io.IOException;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importjavax.xml.parsers.ParserConfigurationException;importjavax.xml.transform.OutputKeys;importjavax.xml.transform.Transformer;importjavax.xml.transform.TransformerFactory;importjavax.xml.transform.dom.DOMSource;importjavax.xml.transform.stream.StreamResult;importorg.w3c.dom.Document;importorg.w3c.dom.Element;importorg.w3c.dom.NodeList;importorg.xml.sax.SAXException;publicclassDomUtil{publicstaticDocumentgetDocument(StringfileAddress){Documentdoc=null;try{DocumentBuilderFactorydbf=DocumentBuilderFactory.newInstance();DocumentBuilderdb=dbf.newDocumentBuilder();doc=db.parse(fileAddress);}catch(Exceptione){e.printStackTrace();}if(doc!=null)returndoc;elsereturnnull;}publicstaticvoidsaveDocument(Documentdoc,StringfileAddress){//保存try{TransformerFactorytf=TransformerFactory.newInstance();Transformert=tf.newTransformer();DOMSourcedoms=newDOMSource(doc);//获得数据源//设置字符编码类型t.setOutputProperty(OutputKeys.ENCODING,UTF-8);StreamResultresult=newStreamResult(newFileOutputStream(fileAddress));t.transform(doms,result);}catch(Exceptione){e.printStackTrace();}}}packagetest;importservice.impl.Login;publicclassStart{publicstaticvoidmain(String[]args){newLogin().start();}}packageservice;publicinterfaceUserService{publicvoidmenu();//查看全部电影publicvoidgetAll();//通过电影名称查询电影publicvoidgetByName();//通过放映时间查询电影publicvoidgetByItem();//购买普通票publicvoidbyTicket();//购买学生折扣票publicvoidbyDiscount();//购买免费票优惠券publicvoidbyFree();}packageservice;publicinterfaceAdminService{//菜单publicvoidmenu();//查看所有publicvoidgetAll();//添加电影publicvoidaddFilm();//删除电影publicvoiddelFilm();//更新电影publicvoidupFilm();//售票查询publicvoidgetTicket();}packageservice.impl;importjava.util.ArrayList;importjava.util.List;importjava.util.Scanner;importdao.impl.FilmDaoImpl;importentity.Film;importentity.Seat;importservice.UserService;publicclassUserLoginimplementsUserService{Scannerinput=newScanner(System.in);ListFilmlistFilm=newArrayListFilm();ListSeatlistSeat=newArrayListSeat();FilmDaoImplfdi=newFilmDaoImpl();publicvoidmenu(){System.out.println(选择你的操作:1:查看所有电影;2:按电影名查询;3:按播放时间查询;+4:购票;5:返回上一层;6:退出;);intchose=input.nextInt();switch(chose){case1:getAll();break;case2:getByName();break;case3:getByItem();break;case4:byTicket();break;case5:break;case6:System.exit(0);break;default:break;}}publicvoidgetAll(){System.out.println(序号+\t+电影名称+\t+英文名称+\t+导演+\t+演员+\t+影片类型+\t+票价+\t+播放时间);listFilm=fdi.getAll();for(Filmfilm:listFilm){System.out.println(film.getId()+\t+film.getName()+\t+film.getPoster()+\t+film.getDirector()+\t+film.getAcotr()+\t+film.getType()+\t+film.getPrice()+\t+film.getItem());}listFilm.clear();menu();}publicvoidgetByName(){System.out.println(请输入要查询到电影:);Stringname=input.next();listFilm=fdi.getByName(name);if(listFilm!=null){System.out.println(序号+\t+电影名称+\t+英文名称+\t+导演+\t+演员+\t+影片类型+\t+票价+\t+播放时间);for(Filmfilm:listFilm){System.out.println(film.getId()+\t+film.getName()+\t+film.getPoster()+\t+film.getDirector()+\t+film.getAcotr()+\t+film.getType()+\t+film.getPrice()+\t+film.getItem());}listFilm.clear();menu();}else{System.out.println(不存在该电影);this.getByName();}}publicvoidgetByItem(){System.out.println(请输入时间段:);StringItem=input.next();//listFilm=fdi.getByItem(15:00);listFilm=fdi.getByItem(Item);if(listFilm!=null){System.out.println(序号+\t+电影名称+\t+英文名称+\t+导演+\t+演员+\t+影片类型+\t+票价+\t+播放时间);for(Filmfilm:listFilm){System.out.println(film.getId()+\t+film.getName()+\t+film.getPoster()+\t+film.getDirector()+\t+film.getAcotr()+\t+film.getType()+\t+film.getPrice()+\t+film.getItem());}listFilm.clear();}else{System.out.println(该时间段没有电影);}menu();}publicvoidbyTicket(){System.out.println(请输入电影名:);Stringname=input.next();System.out.println(请输入播放时间:);Stringitem=input.next();//返回该电影的座位信息//Seatseat=fdi.getSeates(中国功夫,15:00);Filmfilm=newFilm(name,item);Seatseat=fdi.getSeates(film);if(seat!=null){StringticketType=null;booleanflagTicketType=true;while(flagTicketType){System.out.println(请选择票的种类:1:普通票;2:学生票;3:免费票;);intchose=input.nextInt();switch(chose){case1:ticketType=普通票;flagTicketType=false;break;case2:ticketType=学生票;flagTicketType=false;break;case3:ticketType=免费票;flagTicketType=false;break;default:System.out.println(输入错误选项!!!);break;}}printSeat(seat);//输出座位信息booleanflagIndex=true;Stringindex=null;while(flagIndex){System.out.println(请选择座位:);index=input.next();if(seat.isSold(index)){//该座位已经卖出System.out.println(该座位已经卖出!!!);}else{flagIndex=false;}}fdi.buyTicket(film,index,ticketType);System.out.println(购票成功!!!);menu();}else{System.out.println(该电影不存在,或该电影没有此播放时间!!!);this.byTicket();}}@OverridepublicvoidbyDiscount(){//TODOAuto-generatedmethodstub}@OverridepublicvoidbyFree(){//TODOAuto-generatedmethodstub}//座位信息publicvoidprintSeat(Seatseat){System.out.println(************************屏幕************************);for(inti=0;i7;i++){for(intj=0;j7;j++){System.out.print(seat.getSeats()[i][j]+\t);}System.out.println();}}}packageservice.impl;importjava.ut
本文标题:电影院售票管理系统
链接地址:https://www.777doc.com/doc-4481947 .html