《面向对象程序设计》课程设计报告微型酒店管理系统.doc
成绩 徐州工程学院面向对象程序设计课程设计报告 设 计 名 称 微型酒店管理系统 学 院 信电工程学院 专 业 计算机科学与技术 班 级 09软件1班 学 生 姓 名 朱荣博 学 号 20090501157 设 计 地 点 计算机应用技术实验室 指 导 教 师 胡局新 设计起止时间:2012年1月 2日至 2012年 1月 6日 一、 目的及意义本次课程设计选择的题目是为了能让自己更好的掌握所学的知识,本次的课程设计是模拟一个微型的酒店管理系统,或许并不完善但是也是把自己所学的知识融会贯通了。本次课程设计用到图形用户界面设计,数组,字符串处理,以及顺序,循环,选择3种结构等知识。做了此次课程设计让我对本学期学习的知识有了更加深入的了解,使我以后学习相关知识打下了坚实的基础。二、 设计方案2.1课题概述 自定义一个java程序用于实现微型酒店的管理。具体可通过号码的添加来添加住入酒店的住户。当出现各种输入错误时,程序都会弹出对话框来提醒管理者,真正实现了人机交互的思想。2.2功能结构图和流程图程序运行开始 选择房间类型房间有空余 否 是登记成功结账付款程序运行结束。3、具体实现过程3.1 程序运行界面import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;public class MyGui static int a=30;static int b=20;static int c=10;static int d=0;static JTextField t1=new JTextField();static String aa="A","B","C"static JComboBox JC1=new JComboBox(aa);static JTextArea t2=new JTextArea(3,3);static JTextField t3=new JTextField();static JTextField t4=new JTextField();static JTextField t5=new JTextField();static room rooma=new room30;static room roomb=new room20;static room roomc=new room10;static String number=new String60;static boolean tt=true;public static void main(String args) /布置整体的窗口属性JFrame myframe= new JFrame("酒店管理系统");myframe.setLayout(null);myframe.setVisible(true);myframe.setSize(400,580);myframe.setLocation(350, 100);myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/添加"添加"按钮JButton b1=new JButton("添加");b1.addActionListener(new A();b1.setBounds(50,200,130,60);/添加"退出"按钮JButton b2=new JButton("退出");b2.addActionListener(new B();b2.setBounds(50,270,130,60);/添加"结算"按钮JButton b3=new JButton("结算");b3.addActionListener(new C();b3.setBounds(190,200,130,60);JButton b4=new JButton("制作者");b4.addActionListener(new D();b4.setBounds(190,270,130,60);/添加5个标签及文本框JLabel l1=new JLabel("号码");l1.setBounds(10, 110, 30, 30);t1.setBounds(40,110,200,30);JLabel l2=new JLabel("类型");l2.setBounds(10, 150, 30, 30);t2.setBounds(10,10,370,30);JLabel l3=new JLabel("A类房间数");l3.setBounds(10,50,70,30);t3.setText("30");t3.setBounds(72,50,40,30);JLabel l4=new JLabel("B类房间数");l4.setBounds(140,50,70,30);t4.setText("20");t4.setBounds(202,50,40,30);JLabel l5=new JLabel("C类房间数");l5.setBounds(270,50,70,30);t5.setText("10");t5.setBounds(332,50,40,30);/添加其它组件JC1.setBounds(40,150,50,30);/添加功能标签JLabel l6=new JLabel("1.默认同一号码只能住一种类型且只能住一间房间");l6.setBounds(10, 340, 300, 30);JLabel l7=new JLabel("2.添加时当号码为空和号码重复 时会提醒出错");l7.setBounds(10, 371, 300, 30);JLabel l8=new JLabel("5.结算时当号码为空或者不存在会提醒出错");JLabel l9=new JLabel("4.结算时当类型与号码不匹配时会提醒出错");l9.setBounds(10, 433, 300, 30);JLabel l10=new JLabel("6.本程序模拟的金额计算采用随机数,实际的计算方法并不一样");l8.setBounds(10, 464, 370, 30);JLabel l11=new JLabel("3添加成功相应的房间数减1,当房间数为0时则无法继续添加");l10.setBounds(10,495,370,30);l11.setBounds(10, 402, 370, 30);/添加组件到窗体中去myframe.add(l1);myframe.add(t1);myframe.add(l2);myframe.add(JC1);myframe.add(l3);myframe.add(t3);myframe.add(l4);myframe.add(t4);myframe.add(l5);myframe.add(t5);myframe.add(b1);myframe.add(b2);myframe.add(b3);myframe.add(b4);myframe.add(t2);myframe.add(l6);myframe.add(l7);myframe.add(l8);myframe.add(l9);myframe.add(l10);myframe.add(l11);class roomString telephonenumber;String type;3.2 添加按钮功能代码import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JOptionPane;public class A extends MyGui implements ActionListenerpublic void actionPerformed(ActionEvent e)if(t1.getText().length()=0)JOptionPane.showMessageDialog(null,"号码为空,无法添加"); elsefor(int k=0;k<d;k+) if(t1.getText().equals(numberk) JOptionPane.showMessageDialog(null,"号码已存在,无法添加");tt=false; if(tt) if(JC1.getSelectedItem().equals("A") a-; if(a<0)JOptionPane.showMessageDialog(null,"无剩余A类房间数,无法添加");a+; else t3.setText(""+a); rooma29-a=new room();rooma29-a.type="A"rooma29-a.telephonenumber=t1.getText();numberd=t1.getText();d+;JOptionPane.showMessageDialog(null,"添加成功");t1.setText(""); if(JC1.getSelectedItem().equals("B")b-;if(b<0)JOptionPane.showMessageDialog(null,"无剩余B类房间数,无法添加");b+;elset4.setText(""+b);roomb19-b=new room();roomb19-b.type="B"roomb19-b.telephonenumber=t1.getText();numberd=t1.getText();d+;JOptionPane.showMessageDialog(null,"添加成功");t1.setText(""); if(JC1.getSelectedItem().equals("C")c-;if(c<0)JOptionPane.showMessageDialog(null,"无剩余C类房间数,无法添加");c+;elset5.setText(""+c);roomc9-c=new room();roomc9-c.type="C"roomc9-c.telephonenumber=t1.getText();numberd=t1.getText();d+;JOptionPane.showMessageDialog(null,"添加成功");t1.setText(""); tt=true;t1.setText(""); 3.3 退出按钮功能代码import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class B extends MyGui implements ActionListenerpublic void actionPerformed(ActionEvent e) System.exit(0);3.4结算按钮功能代码import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JOptionPane;public class C extends MyGui implements ActionListenerpublic void actionPerformed(ActionEvent e)if(number0=null)JOptionPane.showMessageDialog(null,"号码还没添加,请先添加");t2.setText("");else if(t1.getText().length()=0)JOptionPane.showMessageDialog(null,"号码为空,无法结算");t2.setText("");elsefor(int j=0;j<d;j+)if(t1.getText().equals(numberj)break;else if(j=d-1)JOptionPane.showMessageDialog(null,"号码不存在,无法结算");tt=false;t2.setText("");if(JC1.getSelectedItem().equals("A")for(int i=0;i<30-a;i+)if(t1.getText().equals(roomai.telephonenumber)t2.setText("号码为"+roomai.telephonenumber+"类型为A"+"的费用为"+10*(int)(10*Math.random()+1);break;else if(i=29-a&&tt)JOptionPane.showMessageDialog(null,"号码与类型不匹配,无法结算");t2.setText("");tt=true;if(JC1.getSelectedItem().equals("B")for(int i=0;i<20-b;i+)if(t1.getText().equals(roombi.telephonenumber)t2.setText("号码为"+roombi.telephonenumber+"类型为B"+"的费用为"+100*(int)(10*Math.random()+1);break;else if(i=19-b&&tt)JOptionPane.showMessageDialog(null,"号码与类型不匹配,无法结算");t2.setText("");tt=true;if(JC1.getSelectedItem().equals("C")for(int i=0;i<10-c;i+)if(t1.getText().equals(roomci.telephonenumber)t2.setText("号码为"+roomci.telephonenumber+"类型为C"+"的费用为"+1000*(int)(10*Math.random()+1);break;else if(i=9-c&&tt)JOptionPane.showMessageDialog(null,"号码与类型不匹配,无法结算");t2.setText("");tt=true;t1.setText("");3.5 制作者按钮功能代码import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JOptionPane;public class D extends MyGui implements ActionListenerpublic void actionPerformed(ActionEvent e)JOptionPane.showMessageDialog(null,"制作者:班级:09软件一班, 姓名:朱荣博 ,学号:20090501157");三、 总结与体会 设计一个课程设计需要不断的调试,编程不可能一步到位。即使完成了自己所想到的功能也可以借鉴其它作品的功能使自己的程序更加完整。在编写过程中,当遇到问题是可以借组API文档查询,也可以百度java吧寻求帮助等。编写一个程序也是一个不断学习的过程,对掌握知识非常有帮助。希望通过本次课程设计,对于进一步的java学习有深入的帮助。指导教师签字: 年 月 日