Java 航空系统设计

Java 航空系统设计

1.设计要求
(1)设计每条航线所涉及的信息,如终点站名、航班号、飞机号、飞机周日(星期几)、乘员定额、余票量、订定票的客户名单(包括姓名、订票量、舱位等级1,2或3)等;
(2)结合基本操作的单链表、队列、二叉树等数据结构以及排序算法,设计机票系统的查询、订票、退票等功能;
(3)设计并实现人机交互友好的界面或菜单。

2.总体设计流程
在这里插入图片描述

(1)订票板块
在这里插入图片描述
(2)查询板块
在这里插入图片描述
(3)退票板块
在这里插入图片描述
3.代码实现

  1. 订票界面
    (1)该界面只有一个book类继承了JFrame,同时实现了ActionListener接口与MouseListener接口,实现用户信息的录入,购买航班的选择以及最终的操作确定。
    (2)该部分涉及了Java中输入输出流的使用,通过定义两个文件写入与文件读取函数,实现用户信息的显示与存储。
    (3)对于相关航班余票量的动态变化同样采取文件写入的方式,当选择具体航班后,按行读取原文件中的对应余票量存入数组中,随后对相应下标的数组元素进行自减操作,实现余票量的减少。
    主要函数:
 public void addcustomer() {
		 String filefolderString="D:\\filepath";
			File aFile = new File(filefolderString);
			File[] fileList = aFile.listFiles();	       
	    		   try {
	    		   writemessage(fileList[key]);    		
	    		   }catch(Exception e1) {}
	    	   
	 }
	 public void writeFile(String filename) {
		 try {
	            FileOutputStream fos = new FileOutputStream(filename,true);
	          for(int i=0;i<resttickets.length;i++) {
	        	  String str=String.valueOf(resttickets[i]);
	        	  byte[] b = str.getBytes();
	        	  fos.write(b);
		            fos.write('\n');
		      
	          }
	          fos.close(); 
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	 }
	 public void clear()   {
		        try {
		           
		            FileWriter fileWriter =new FileWriter(restfile);
		            fileWriter.write("");
		            fileWriter.flush();
		            fileWriter.close();
		        } catch (IOException e) {
		            e.printStackTrace();
		        }
		    
	 }
	 public void writemessage(File file){
	        try {
	            FileOutputStream fos = new FileOutputStream(file,true);
	            OutputStreamWriter write=new OutputStreamWriter(fos,"gbk");
	        	  String s1=tfname.getText();
	        	  String s3=tfid.getText();
	        	  String s2=String.valueOf(lever.getSelectedItem());
	        	  String str=s1+"	"+s3+"       "+"1"+"    "+s2;	        	 // System.out.println(str);
	        	  BufferedWriter writer=new BufferedWriter(write);
	        	  writer.write("\n"+str);
	        	  writer.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        
	    }

public static void main(String[] args)throws Exception{
	new bookjf();
	
}

public void mouseClicked(MouseEvent e) {
	if(e.getSource()==jb1) {
		resttickets[key]--;
       this.clear();
       this.writeFile("D:\\余票列表.txt");
       this.addcustomer();
       JOptionPane.showMessageDialog(this,"尊敬的乘客您好!恭喜您购票成功!");
	}
	else {
		javax.swing.JOptionPane.showMessageDialog(this,"本次购票已取消");
	}
	
}

2.退票界面
(1)该界面只有一个cancel类继承了JFrame,同时实现了ActionListener接口与MouseListener接口,实现用户信息的录入,欲退票买航班的选择以及最终的操作确定。
(2)该部分涉及了Java中输入输出流的使用,通过定义两个文件写入与文件读取函数,按行读取原文件中的对应乘客信息存入链表中,再将现有文本框中的信息与之进行比对,实现用户信息的正确删除。
(3)对于相关航班余票量的动态变化同样采取文件写入的方式,当选择具体航班且比对无误后,按行读取原文件中的对应余票量存入数组中,随后对相应下标的数组元素进行自增操作,实现余票量的增加。

public void customerdisplay(File file)throws Exception {

	BufferedReader cus=null;
	String s3;
	JFrame jf1=new JFrame("*乘客信息单*");
	JTextArea jta1=new JTextArea();
	ArrayList<String>customerlist =new ArrayList<String>();
	FileInputStream fi = new FileInputStream(file);
	InputStreamReader isr = new InputStreamReader(fi,"gbk");
	cus=new BufferedReader(isr);	
	while(true) {
		
		s3= cus.readLine();
		System.out.println(s3);
		if(s3!=null)
		{
			customerlist.add(s3);
	}
		else
		break;
	}
	String title="姓名"+"	"+"身份证号"+"   "+"购票数"+	"   "+"舱位"+"\n";
	jta1.append(title);
	for(int i=0;i<customerlist.size();i++) {
		jta1.append(customerlist.get(i)+"\n");

	}
	
	
	jf1.add(jta1);
	jta1.setFont(new Font("黑体",Font.BOLD,16));
	jta1.setForeground(Color.BLACK);
	jta1.setBounds(0,0,jf1.getWidth(),jf1.getHeight());
	jta1.setBackground(Color.BLACK);
	jta1.setEnabled(false);
	jf1.setResizable(false);
	jf1.setVisible(true);
	jf1.setSize(300, 600);
	
}
  
	public static void main(String[] args)throws Exception{
		new queryjf();
	}

3.查询界面
(1)该界面只有一个query类继承了JFrame,同时实现了ActionListener接口,实现所有航班信息的显示以及具体航班乘客列表的查询显示。
(2)该部分涉及了Java中输入输出流的使用,通过定义文件读取函数,按行读取原文件中的对应乘客信息存入链表中 ,再通过遍历打印将其显示在主界面的查询文本框中。
(3)对于相关航班乘客列表的查询,由下拉框控制,当选择下拉框中的具体班次时,该类将作出反应,自动弹出新的界面,将乘客信息按行读取到链表中,再遍历打印至新的界面文本框中。

 public void deletcustomer(String id) {
		 String filefolderString="D:\\filepath";
			File aFile = new File(filefolderString);
			File[] fileList = aFile.listFiles();	       
	    		   try {
	    		   deletmessage(id,fileList[key]);    		
	    		   }catch(Exception e1) {}
	    	   
	 }

	 public void deletmessage(String str,File file)throws Exception {
		 String s2=null;
		 boolean have=false;
		 BufferedReader deletinf=null;
		 ArrayList<String> newmessage=new ArrayList<String>();
		 FileInputStream deletfi= new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(deletfi,"gbk");
			deletinf=new BufferedReader(isr);	
				while(true) {
				s2= deletinf.readLine();
				if(s2==null)break;
				if(s2.contains(str)) {
					System.out.println(str);
					System.out.println(s2);
					have=true;}				
				else if(!s2.contains(str))
				{newmessage.add(s2);	
				}}	
				if(!have) {
					JOptionPane.showMessageDialog(this,"对不起,查不到您的订单信息!请检查您的账号与身份证号是否正确!");}				
				else {
					resttickets[key]++;
					 this.clear();
				     this.writeFile("D:\\余票列表.txt");
			try {		           
	            FileWriter fileWriter =new FileWriter(file);
	            fileWriter.write("");
	            fileWriter.flush();
	            fileWriter.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
			PrintStream ps = new PrintStream(file);
            for(int i=0;i<newmessage.size();i++){ 
                            ps.print(newmessage.get(i)+"\n");   }
	            JOptionPane.showMessageDialog(this,"尊敬的乘客您好!提醒您退票成功!");
				}
	 }
	 public static void main(String[] args)throws Exception{
			new canceljf();

		}
	 public void writeFile(String filename) {
		 try {
	            FileOutputStream fos = new FileOutputStream(filename,true);
	          for(int i=0;i<resttickets.length;i++) {
	        	  String str=String.valueOf(resttickets[i]);
	        	  byte[] b = str.getBytes();
	        	  fos.write(b);
		            fos.write('\n');		      
	          }
	          fos.close(); 
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	 }
	 public void clear()   {
		        try {
		           
		            FileWriter fileWriter =new FileWriter(restfile);
		            fileWriter.write("");
		            fileWriter.flush();
		            fileWriter.close();
		        } catch (IOException e) {
		            e.printStackTrace();
		        }
		    
	 }
	public void actionPerformed(ActionEvent e) {
		JComboBox jcmbType = (JComboBox) e.getSource();
		
	       for(int i=0;i<bancilist.size();i++) {
	    	  
	    	   if(jcmbType.getSelectedItem()==bancilist.get(i)) {
	    		   key=i;
	    	   }
	    	   
		}
		
	}
	public void mouseClicked(MouseEvent e) {
		if(e.getSource()==jb1) {
			//
		     this.deletcustomer(tfid.getText());    
	     
		}
		else {
			javax.swing.JOptionPane.showMessageDialog(this,"本次退票已取消");
		}
		
	}

4.主页面界面
主界面继承了JFrame,同时实现了ActionListerner接口,在主界面上放置所有功能按钮,通过使用Java中的相关封装包,实现每次按下不同按钮,生成不同功能界面。

public void actionPerformed(ActionEvent e) {
		if(e.getSource()==queryjb){
			queryjf qjf = null;
			try {
				qjf = new queryjf();
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			}
		else if(e.getSource()==bookjb){
			bookjf bjf = null;
			try {
				bjf = new bookjf();
			} catch (Exception e1) {
				
				e1.printStackTrace();
			}
			}
		else {
			canceljf cjf = null;
			try {
				cjf = new canceljf();
			} catch (Exception e1) {
				
				e1.printStackTrace();
			}
		}
		}
	
	//主函数入口:
	public static void main(String[] args)throws Exception{
	new TicketsFrame();
	}

4.实验结果
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
目 录 前 言 1 第1章 需求分析 2 §1.1 开发必要性 2 §1.2 可行性分析 2 §1.2.1 经济可行性分析 2 §1.2.2 技术可行性分析 3 §1.2.3 现有系统的分析 3 第2章 系统分析 4 §2.1 系统逻辑模型的提出 4 §2.2 系统的功能介绍 4 §2.3 系统开发工具和开发语言 5 §2.3.1 开发工具 5 §2.3.2 开发语言 6 第3章 总体设计 7 §3.1 系统功能设计 7 §3.2 系统功能模块简介 7 第4章 数据库设计 10 §4.1 概念结构设计 10 §4.2 逻辑结构设计 11 §4.3 物理结构设计 12 第5章 详细设计 14 §5.1 关键业务流程描述 14 §5.1.1 航空售票管理 14 §5.1.2 管理员管理流程 14 §5.2 系统界面设计 15 §5.2.1 主功能界面 15 §5.2.2 其他功能界面 16 §5.3 模块代码实现 18 §5.3.1 航空订票查询模块 18 §5.3.2 航空售票管理模块 19 第6章 系统测试 21 §6.1 软件测试的目标 21 §6.2 具体测试 21 结 论 24 参考文献 25 致 谢 27 §5.3.1 航空订票查询模块 航空订票查询主要实现对票据信息种类的添加、修改和删除功能。票据信息种类是系统内容的最高级别,所以在添加、修改或删除票据信息时,也必须选择该票据信息所属的票据信息种类。下面是票据信息种类的添加、修改和删除功能的主要实现代码。 public void actionPerformed(ActionEvent e) { this.flightNumber = flightField.getText().trim(); if (flightNumber.length() == 0) //未输入信息 { JOptionPane.showMessageDialog(null,"请输入航班号或者从列表中选择", "错误信息",JOptionPane.ERROR_MESSAGE); return; } executeFlightQuery(); } public void executeFlightQuery() { String sqlString = "SELECT DISTINCT * FROM " +"flight " + "WHERE flight=" + "\'" + flightNumber + "\'"; ResultSet rs = sqlBean.executeQuery(sqlString); if (rs != null) showResult(rs); else JOptionPane.showMessageDialog(null,"没有连接上数据库!", "错误信息",JOptionPane.ERROR_MESSAGE); } 以上是对数据添加的程序代码,该段代码实现了获得用户数据输入,并把数据插入到数据库当中的功能。 。。。。。。。。。。。。。。。。。。。。。。。。。。。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值