1、电影院售票管理系统722020年4月19日文档仅供参考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.tra
2、nsform.Transformer;import javax.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 stat
3、ic Document getDocument(String 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
4、 saveDocument(Document doc,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(fil
5、eAddress);t.transform(doms, 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();/经过电影名称查询电影publ
6、ic void getByName();/经过放映时间查询电影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();/更新电
7、影public void upFilm();/售票查询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=n
8、ew Scanner(System.in);List 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;ca
9、se 3:getByItem();break;case 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
10、()+t+film.getDirector()+t+film.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+影片类
11、型+t+票价+t+播放时间);for (Film film : 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();pu
12、blic void getByItem() System.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
13、() + t+ film.getPoster() + 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(请输入播放时间:);Stri
14、ng item=input.next();/ 返回该电影的座位信息/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
15、();switch (chose) case 1:ticketType = 普通票;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.
16、out.println(请选择座位:);index = 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-gene
17、rated method stubOverridepublic 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.Adm
18、inService;import entity.AdminUser;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
19、.out.println(请输入密码:);String 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()
20、;break;this.start();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.AdminService;public class AdminLogin implements AdminServiceScanner input=new Scanner(System.in);List li
21、st=new ArrayList();FilmDaoImpl 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
22、;case 6:break;case 7:System.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
23、()+t+film.getName()+t+film.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
24、(请输入导演:);String director=input.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
25、, type, price, item);/Film 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,
26、item);boolean exist=fdi.delateFilm(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(请输入要修改的放映时间:);Strin
27、g item=input.next();System.out.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(
28、message)case 0:System.out.println(更新成功!);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.nex
29、t();System.out.println(请输入电影播放时间:);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().getStudent
30、Num();System.out.println(免费票: + 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 entit
31、y;public class Ticket private 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:
32、break;public int getOrdinaryNum() 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 setFr
33、eeNum(int freeNum) this.freeNum = 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(in
34、t i=0;i7;i+)for(int j=0;j7;j+)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 = tic
35、ket;public Film getFilm() return 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(!se
36、atsa-1b-1.equals(index)return 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
37、 String Item; /放映时间public Film()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;Pri
38、ce = price;Item = item;public 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() return 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;
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100