一、需求分析
1.设计题目:车票管理系统
用JAVA语言和数据结构知识设计设计车票管理系统。要求如下所述:
一车站每天有n个发车班次,每个班次都有一个班次号(1、2、3…n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。如:
班次 发车时间 起点站 终点站 行车时间 额定载量 已定票人数
1 8:00 武汉 广州 2 45 30
2 6:30 武汉 成都 3 40 40
3 7:00 武汉 成都 3 40 20
4 10:00 武汉 成都 3 40 2
…
根据以上情况设计出相应的车票管理系统,具体功能如下:
1) 录入功能
录入班次信息,可不定时地增加班次数据
2) 浏览功能
浏览班次信息,可显示出所有班次当前状况(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。
3) 查询功能
查询路线:可按班次号查询,可按终点站查询。
4) 售票功能
当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数。
5) 退票功能
退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数。
6) 文件保存
可自行增加其他符合业务逻辑的功能
2. 设计要求
a.根据题目功能需求,自己定义合适的存储结构、类、参数等;
b.提供友好的用户界面,方便用户操作。
3. 系统功能需求分析
a. 录入班次信息,可不定时地增加班次数据。
b. 浏览班次信息,可显示出所有班次当前状况(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。
c. 查询路线:可按班次号查询,可按终点站查询。
d. 当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数。
f. 退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数。
二、概要设计
1.系统总体设计框架
2. 系统功能模块图
三、详细设计
四、主要源程序代码
主界面:
public class TrainTicket extends JFrame implements ActionListener{
JButton Add, ViewAll, Serach, SellTicket,ReturnTicket, Delete;
TicketAdd Add_method;
TicketAdd2 Add2_method;
TicketViewAll ViewAll_method;
TicketSerach Serach_method;
TicketReturn Return_method;
TicketSell Sell_method;
TicketDelete Delete_method;
public static final List TrainList = new ArrayList();
public TrainTicket(){
try {
FileWriter out = new FileWriter("word.txt");
out.close();
} catch (IOException e) {
}
setBounds(400, 100, 700, 500);
JPanel panel = new JPanel();
setContentPane(panel);
panel.setLayout(null);
JLabel label = new JLabel("欢迎进入车票管理系统");
label.setFont(new Font("BOLD", Font.BOLD, 28));
panel.add(label);
label.setBounds(200, 20, 400, 100);
Add = new JButton("录入");
panel.add(Add);
Add.setBounds(50,200,80,50);
ViewAll = new JButton("浏览");
panel.add(ViewAll);
ViewAll.setBounds(150,200,80,50);
Serach = new JButton("查询");
panel.add(Serach);
Serach.setBounds(250,200,80,50);
SellTicket = new JButton("售票");
panel.add(SellTicket);
SellTicket.setBounds(350,200,80,50);
ReturnTicket = new JButton("退票");
panel.add(ReturnTicket);
ReturnTicket.setBounds(450,200,80,50);
Delete = new JButton("删除");
panel.add(Delete);
Delete.setBounds(550,200,80,50);
Add.addActionListener(this);
ViewAll.addActionListener(this);
Serach.addActionListener(this);
SellTicket.addActionListener(this);
ReturnTicket.addActionListener(this);
Delete.addActionListener(this);
setVisible(true);
}
public static void main(String[] args){
TrainTicket kk = new TrainTicket();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub if(e.getSource() == Add)
Add2_method = new TicketAdd2();
if(e.getSource() == ViewAll)
ViewAll_method = new TicketViewAll();
if(e.getSource() == Serach)
Serach_method = new TicketSerach();
if(e.getSource() == SellTicket)
Sell_method = new TicketSell();
if(e.getSource() == ReturnTicket)
Return_method = new TicketReturn();
if(e.getSource() == Delete)
Delete_method = new TicketDelete();
}
}
录入班次信息:
public class TicketAdd extends JFrame implements ActionListener{
JTextField NumText, TimeText, StartText, EndText, DuringText, MaxText, PersonText;
File file = new File("word.txt");
JButton b1, b2, b3;
private String Num, Time, Start, End, During, Max, Have,Person;
public TicketAdd() {
Container c = this.getContentPane();
c.setLayout(null);
JLabel label = new JLabel("录入班次信息");
label.setFont(new Font("TRUE", Font.TRUETYPE_FONT, 20));
label.setBounds(190, 15, 500, 100);
c.add(label);
NumText = new JTextField(15);
NumText.setBounds(220, 115, 125, 15);
TimeText = new JTextField(15);
TimeText.setBounds(220, 140, 125, 15);
StartText = new