《电影院售票管理系统方案.doc》由会员分享,可在线阅读,更多相关《电影院售票管理系统方案.doc(32页珍藏版)》请在课桌文档上搜索。
1、package util;import java.io.FileOutputStream;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import javax.xml.transform.OutputKeys;import javax.xml.transform.Transformer;import j
2、avax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMSource;import javax.xml.transform.stream.StreamResult;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;public class DomUtil public static Document getDocument(Str
3、ing fileAddress)Document doc=null;try DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();DocumentBuilder db=dbf.newDocumentBuilder();doc=db.parse(fileAddress); catch (Exception e) e.printStackTrace(); if(doc!=null)return doc;else return null;public static void saveDocument(Document doc,
4、String fileAddress)/保存tryTransformerFactory tf=TransformerFactory.newInstance();Transformer t=tf.newTransformer();DOMSource doms=new DOMSource(doc);/获得数据源/设置字符编码类型t.setOutputProperty(OutputKeys.ENCODING, UTF-8);StreamResult result =new StreamResult(new FileOutputStream(fileAddress);t.transform(doms,
5、 result); catch (Exception e) e.printStackTrace(); package test;import service.impl.Login;public class Start public static void main(String args) new Login().start();package service;public interface UserService public void menu();/查看全部电影public void getAll();/通过电影名称查询电影public void getByName();/通过放映时间
6、查询电影public void getByItem();/购买普通票public void byTicket();/购买学生折扣票public void byDiscount();/购买免费票 优惠券public void byFree();package service;public interface AdminService /菜单public void menu();/查看所有public void getAll();/添加电影public void addFilm();/删除电影public void delFilm();/更新电影public void upFilm();/售票查询
7、public void getTicket();package service.impl;import java.util.ArrayList;import java.util.List;import java.util.Scanner;import dao.impl.FilmDaoImpl;import entity.Film;import entity.Seat;import service.UserService;public class UserLogin implements UserService Scanner input=new Scanner(System.in);List
8、listFilm=new ArrayList();List listSeat=new ArrayList();FilmDaoImpl fdi=new FilmDaoImpl();public void menu() System.out.println(选择你的操作:1:查看所有电影;2:按电影名查询;3:按播放时间查询; +4:购票;5:返回上一层;6:退出;);int chose=input.nextInt();switch(chose)case 1:getAll() ;break;case 2:getByName();break;case 3:getByItem();break;case
9、 4:byTicket();break;case 5:break;case 6:System.exit(0);break;default :break;public void getAll() System.out.println(序号+t+电影名称+t+英文名称+t+导演+t+演员+t+影片类型+t+票价+t+播放时间);listFilm=fdi.getAll();for(Film film:listFilm)System.out.println(film.getId()+t+film.getName()+t+film.getPoster()+t+film.getDirector()+t+f
10、ilm.getAcotr()+t+film.getType()+t+film.getPrice()+t+film.getItem();listFilm.clear();menu();public void getByName() System.out.println(请输入要查询到电影:);String name=input.next();listFilm=fdi.getByName(name);if (listFilm != null) System.out.println(序号+t+电影名称+t+英文名称+t+导演+t+演员+t+影片类型+t+票价+t+播放时间);for (Film fi
11、lm : 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();elseSystem.out.println(不存在该电影);this.getByName();public void getByItem() Syste
12、m.out.println(请输入时间段:);String Item=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 (Film film : listFilm) System.out.println(film.getId() + t + film.getName() + t+ film.getPoster() +
13、t + film.getDirector() + t+ film.getAcotr() + t + film.getType() + t+ film.getPrice() + t + film.getItem();listFilm.clear();elseSystem.out.println(该时间段没有电影);menu();public void byTicket() System.out.println(请输入电影名:);String name=input.next();System.out.println(请输入播放时间:);String item=input.next();/ 返回该电
14、影的座位信息/Seat seat = fdi.getSeates(中国功夫, 15:00);Film film=new Film(name, item);Seat seat = fdi.getSeates(film);if (seat != null) String ticketType = null;boolean flagTicketType=true;while(flagTicketType)System.out.println(请选择票的种类:1:普通票;2:学生票;3:免费票;);int chose = input.nextInt();switch (chose) case 1:ti
15、cketType = 普通票;flagTicketType=false;break;case 2:ticketType = 学生票;flagTicketType=false;break;case 3:ticketType = 免费票;flagTicketType=false;break;default:System.out.println(输入错误选项!);break;printSeat(seat);/输出座位信息boolean flagIndex=true;String index=null;while(flagIndex)System.out.println(请选择座位:);index =
16、 input.next();if(seat.isSold(index)/该座位已经卖出System.out.println(该座位已经卖出!);elseflagIndex=false;fdi.buyTicket(film, index, ticketType);System.out.println(购票成功!);menu();elseSystem.out.println(该电影不存在,或该电影没有此播放时间!);this.byTicket();Overridepublic void byDiscount() / TODO Auto-generated method stubOverridepu
17、blic void byFree() / TODO Auto-generated method stub/座位信息public void printSeat(Seat seat)System.out.println(*屏幕*);for(int i=0;i7;i+)for(int j=0;j7;j+)System.out.print(seat.getSeats()ij+t);System.out.println();package service.impl;import java.util.Scanner;import service.AdminService;import entity.Adm
18、inUser;public class Login Scanner input =new Scanner(System.in);public void start()System.out.println(请选择登陆方式:1:管理员登录;2:普通用户登录;3:退出;);int chose=input.nextInt();switch(chose)case 1:/*AdminUser admin=new AdminUser();System.out.println(请输入用户名:);String name=input.next();System.out.println(请输入密码:);String
19、 pwd=input.next();if(name.equals(admin.getUserName()&pwd.equals(admin.getUesrPassword()*/new AdminLogin().menu(); /else System.out.println(用户名和密码不匹配!);break;case 2:new UserLogin().menu();break;case 3:System.exit(0);break;default :System.out.println(输入错误的选择方式!);this.start();break;this.start();package
20、 service.impl;import java.util.ArrayList;import java.util.List;import java.util.Scanner;import dao.impl.FilmDaoImpl;import entity.Film;import entity.Seat;import service.AdminService;public class AdminLogin implements AdminServiceScanner input=new Scanner(System.in);List list=new ArrayList();FilmDaoI
21、mpl fdi=new FilmDaoImpl();public void menu() System.out.println(选择你的操作:1:查看;2:添加;3:删除电影; +4:修改电影;5:售票查询;6:返回上一层;7:退出;);int chose=input.nextInt();switch(chose)case 1:getAll() ;break;case 2:addFilm();break;case 3:delFilm();break;case 4:upFilm();break;case 5:getTicket();break;case 6:break;case 7:System
22、.exit(0);break;default :System.out.println(输入错误的选择方式!);this.menu();break;public void getAll() int num=0;System.out.println(序号+t+电影名称+t+英文名称+t+导演+t+演员+t+影片类型+t+票价+t+播放时间);list=fdi.getAll();/System.out.println(list.size();for(Film film:list)num+;System.out.println(film.getId()+t+film.getName()+t+film.
23、getPoster()+t+film.getDirector()+t+film.getAcotr()+t+film.getType()+t+film.getPrice()+t+film.getItem();list.clear();menu();public void addFilm() System.out.println(请输入电影名称:);String name=input.next();System.out.println(请输入英文名称:);String poster=input.next();System.out.println(请输入导演:);String director=in
24、put.next();System.out.println(请输入演员:);String acotr=input.next();System.out.println(请输入影片类型:);String type=input.next();System.out.println(请输入票价:);String price=input.next();System.out.println(请输入播放时间:);String item=input.next();Film film=new Film(name, poster, director, acotr, type, price, item);/Film
25、film=new Film(东成西就, e-w, 镇伟, 伊健, 喜剧, 150, 15:50);fdi.addFilm(film);System.out.println(添加成功!);menu();public void delFilm() System.out.println(请输入删除的电影名称:);String name=input.next();System.out.println(请输入播放时间(输入all,则全部删除):);String item=input.next();Film film=new Film(name, item);boolean exist=fdi.delat
26、eFilm(film);/boolean exist=fdi.delateFilm(非常完美,time);if(exist)System.out.println(删除成功!);menu();elseSystem.out.println(该电影不存在,或该电影没有此播放时间!);this.delFilm();public void upFilm() System.out.println(请输入要修改的电影名称:);String name=input.next();System.out.println(请输入要修改的放映时间:);String item=input.next();System.ou
27、t.println(请输入要修改的列表名称:);String property=input.next();System.out.println(请输入该列表修改后的值:);String value=input.next();/fdi.updateFilm(蜘蛛侠,14:00,播放时间,15:00);/fdi.updateFilm(蜘蛛侠,14:00,影片类型,搞笑);Film film=new Film(name, item);int message=fdi.updateFilm(film,property,value);switch(message)case 0:System.out.pri
28、ntln(更新成功!);menu();break;case 1:System.out.println(不存在该电影;);this.upFilm();break;case 2:System.out.println(不存在此电影的该播放时间;);this.upFilm();break;case 3:System.out.println(不存在该属性列表;);this.upFilm();break;public void getTicket()System.out.println(请输入电影名称:);String name=input.next();System.out.println(请输入电影播
29、放时间:);String item=input.next();/Film film=new Film(中国功夫, 15:00);Film film=new Film(name,item);Seat seat=fdi.getTicket(film);if (seat != null) printSeat(seat);System.out.println(普通票: + seat.getTicket().getOrdinaryNum();System.out.println(学生票: + seat.getTicket().getStudentNum();System.out.println(免费票:
30、 + seat.getTicket().getFreeNum();menu();elseSystem.out.println(该电影不存在,或该电影没有此播放时间!);this.getTicket();/座位信息public void printSeat(Seat seat)System.out.println(*屏幕*);for(int i=0;i7;i+)for(int j=0;j7;j+)System.out.print(seat.getSeats()ij+t);System.out.println();package entity;public class Ticket private
31、 String type;private int ordinaryNum=0;private int studentNum=0;private int freeNum=0;public String getType() return type;public void setType(String type) this.type = type;switch(type)case 普通票:ordinaryNum+;break;case 学生票:studentNum+;break;case 免费票:freeNum+;break;default:break;public int getOrdinaryN
32、um() return ordinaryNum;public void setOrdinaryNum(int ordinaryNum) this.ordinaryNum = ordinaryNum;public int getStudentNum() return studentNum;public void setStudentNum(int studentNum) this.studentNum = studentNum;public int getFreeNum() return freeNum;public void setFreeNum(int freeNum) this.freeN
33、um = freeNum;package entity;public class Seat private String index;private Ticket ticket;private Film film;private String seats=new String 77;public Seat(String index, Ticket ticket, Film film) this.index = index;this.ticket = ticket;this.film = film;public Seat()for(int i=0;i7;i+)for(int j=0;j7;j+)
34、seatsij=(i+1)+-+(j+1);public String getIndex() return index;public void setIndex(String index) String str=index.split(-);setSeats(Integer.parseInt(str0),Integer.parseInt(str1);public Ticket getTicket() return ticket;public void setTicket(Ticket ticket) this.ticket = ticket;public Film getFilm() retu
35、rn film;public void setFilm(Film film) this.film = film;private void setSeats(int x, int y) seatsx-1y-1=已售;public String getSeats() return seats;public boolean isSold(String index)String str=index.split(-);int a=Integer.parseInt(str0);int b=Integer.parseInt(str1);if(!seatsa-1b-1.equals(index)return
36、true;elsereturn false;package entity;public class Film private int id; /序号private String Name; /电影名称private String Poster; /英文名private String Director; /导演private String Acotr; /演员private String Type; /电影类型private String Price; /电影价格/private String Schedule; /时刻表private String Item; /放映时间public Film
37、()public Film(String name,String item)Name = name;Item = item;public Film(int id, String name, String poster, String director,String acotr, String type, String price, String item) this.id = id;Name = name;Poster = poster;Director = director;Acotr = acotr;Type = type;Price = price;Item = item;public
38、Film(String name, String poster, String director,String acotr, String type, String price, String item) Name = name;Poster = poster;Director = director;Acotr = acotr;Type = type;Price = price;Item = item;public int getId() return id;public void setId(int id) this.id = id;public String getName() retur
39、n Name;public void setName(String name) Name = name;public String getPoster() return Poster;public void setPoster(String poster) Poster = poster;public String getDirector() return Director;public void setDirector(String director) Director = director;public String getAcotr() return Acotr;public void setAcotr(String acotr) Acotr