《面向对象程序设计》课程设计报告.docx

上传人:b****6 文档编号:6230756 上传时间:2023-01-04 格式:DOCX 页数:15 大小:238.67KB
下载 相关 举报
《面向对象程序设计》课程设计报告.docx_第1页
第1页 / 共15页
《面向对象程序设计》课程设计报告.docx_第2页
第2页 / 共15页
《面向对象程序设计》课程设计报告.docx_第3页
第3页 / 共15页
《面向对象程序设计》课程设计报告.docx_第4页
第4页 / 共15页
《面向对象程序设计》课程设计报告.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

《面向对象程序设计》课程设计报告.docx

《《面向对象程序设计》课程设计报告.docx》由会员分享,可在线阅读,更多相关《《面向对象程序设计》课程设计报告.docx(15页珍藏版)》请在冰豆网上搜索。

《面向对象程序设计》课程设计报告.docx

《面向对象程序设计》课程设计报告

成绩

徐州工程学院

面向对象程序设计

课程设计报告

设计名称微型酒店管理系统

学院信电工程学院

专业计算机科学与技术

班级09软件1班

学生姓名朱荣博

学号20090501157

设计地点计算机应用技术实验室

指导教师胡局新

 

设计起止时间:

2012年1月2日至2012年1月6日

一、目的及意义

本次课程设计选择的题目是为了能让自己更好的掌握所学的知识,本次的课程设计是模拟一个微型的酒店管理系统,或许并不完善但是也是把自己所学的知识融会贯通了。

本次课程设计用到图形用户界面设计,数组,字符串处理,以及顺序,循环,选择3种结构等知识。

做了此次课程设计让我对本学期学习的知识有了更加深入的了解,使我以后学习相关知识打下了坚实的基础。

二、设计方案

2.1课题概述

自定义一个java程序用于实现微型酒店的管理。

具体可通过号码的添加来添加住入酒店的住户。

当出现各种输入错误时,程序都会弹出对话框来提醒管理者,真正实现了人机交互的思想。

2.2功能结构图和流程图

 

 

3、具体实现过程

3.1程序运行界面

importjava.awt.*;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.*;

publicclassMyGui{

staticinta=30;

staticintb=20;

staticintc=10;

staticintd=0;

staticJTextFieldt1=newJTextField();

staticStringaa[]={"A","B","C"};

staticJComboBoxJC1=newJComboBox(aa);

staticJTextAreat2=newJTextArea(3,3);

staticJTextFieldt3=newJTextField();

staticJTextFieldt4=newJTextField();

staticJTextFieldt5=newJTextField();

staticroom[]rooma=newroom[30];

staticroom[]roomb=newroom[20];

staticroom[]roomc=newroom[10];

staticString[]number=newString[60];

staticbooleantt=true;

publicstaticvoidmain(String[]args){

//布置整体的窗口属性

JFramemyframe=newJFrame("酒店管理系统");

myframe.setLayout(null);

myframe.setVisible(true);

myframe.setSize(400,580);

myframe.setLocation(350,100);

myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//添加"添加"按钮

JButtonb1=newJButton("添加");

b1.addActionListener(newA());

b1.setBounds(50,200,130,60);

//添加"退出"按钮

JButtonb2=newJButton("退出");

b2.addActionListener(newB());

b2.setBounds(50,270,130,60);

//添加"结算"按钮

JButtonb3=newJButton("结算");

b3.addActionListener(newC());

b3.setBounds(190,200,130,60);

JButtonb4=newJButton("制作者");

b4.addActionListener(newD());

b4.setBounds(190,270,130,60);

//添加5个标签及文本框

JLabell1=newJLabel("号码");

l1.setBounds(10,110,30,30);

t1.setBounds(40,110,200,30);

JLabell2=newJLabel("类型");

l2.setBounds(10,150,30,30);

t2.setBounds(10,10,370,30);

JLabell3=newJLabel("A类房间数");

l3.setBounds(10,50,70,30);

t3.setText("30");

t3.setBounds(72,50,40,30);

JLabell4=newJLabel("B类房间数");

l4.setBounds(140,50,70,30);

t4.setText("20");

t4.setBounds(202,50,40,30);

JLabell5=newJLabel("C类房间数");

l5.setBounds(270,50,70,30);

t5.setText("10");

t5.setBounds(332,50,40,30);

//添加其它组件

JC1.setBounds(40,150,50,30);

//添加功能标签

JLabell6=newJLabel("1.默认同一号码只能住一种类型且只能住一间房间");

l6.setBounds(10,340,300,30);

JLabell7=newJLabel("2.添加时当号码为空和号码重复时会提醒出错");

l7.setBounds(10,371,300,30);

JLabell8=newJLabel("5.结算时当号码为空或者不存在会提醒出错");

JLabell9=newJLabel("4.结算时当类型与号码不匹配时会提醒出错");

l9.setBounds(10,433,300,30);

JLabell10=newJLabel("6.本程序模拟的金额计算采用随机数,实际的计算方法并不一样");

l8.setBounds(10,464,370,30);

JLabell11=newJLabel("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);

}

}

classroom{

Stringtelephonenumber;

Stringtype;

}

3.2添加按钮功能代码

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JOptionPane;

publicclassAextendsMyGuiimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

if(t1.getText().length()==0)JOptionPane.showMessageDialog(null,"号码为空,无法添加");

else{

for(intk=0;k

if(t1.getText().equals(number[k]))

{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);

rooma[29-a]=newroom();

rooma[29-a].type="A";

rooma[29-a].telephonenumber=t1.getText();

number[d]=t1.getText();

d++;

JOptionPane.showMessageDialog(null,"添加成功");

t1.setText("");}

}

if(JC1.getSelectedItem().equals("B")){

b--;

if(b<0){JOptionPane.showMessageDialog(null,"无剩余B类房间数,无法添加");b++;}

else

{t4.setText(""+b);

roomb[19-b]=newroom();

roomb[19-b].type="B";

roomb[19-b].telephonenumber=t1.getText();

number[d]=t1.getText();

d++;

JOptionPane.showMessageDialog(null,"添加成功");

t1.setText("");}

}

if(JC1.getSelectedItem().equals("C")){

c--;

if(c<0){JOptionPane.showMessageDialog(null,"无剩余C类房间数,无法添加");c++;}

else{

t5.setText(""+c);

roomc[9-c]=newroom();

roomc[9-c].type="C";

roomc[9-c].telephonenumber=t1.getText();

number[d]=t1.getText();

d++;

JOptionPane.showMessageDialog(null,"添加成功");

t1.setText("");}

}

}

}tt=true;t1.setText("");

}

}

3.3退出按钮功能代码

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

publicclassBextendsMyGuiimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

System.exit(0);

}

}

3.4结算按钮功能代码

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JOptionPane;

publicclassCextendsMyGuiimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

if(number[0]==null){JOptionPane.showMessageDialog(null,"号码还没添加,请先添加");t2.setText("");}

else{if(t1.getText().length()==0){JOptionPane.showMessageDialog(null,"号码为空,无法结算");t2.setText("");}

else{

for(intj=0;j

if(JC1.getSelectedItem().equals("A")){

for(inti=0;i<30-a;i++){

if(t1.getText().equals(rooma[i].telephonenumber)){

t2.setText("号码为"+rooma[i].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(inti=0;i<20-b;i++){

if(t1.getText().equals(roomb[i].telephonenumber)){

t2.setText("号码为"+roomb[i].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(inti=0;i<10-c;i++){

if(t1.getText().equals(roomc[i].telephonenumber)){

t2.setText("号码为"+roomc[i].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制作者按钮功能代码

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjavax.swing.JOptionPane;

publicclassDextendsMyGuiimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

JOptionPane.showMessageDialog(null,"制作者:

班级:

09软件一班,姓名:

朱荣博,学号:

20090501157");}

}

三、总结与体会

设计一个课程设计需要不断的调试,编程不可能一步到位。

即使完成了自己所想到的功能也可以借鉴其它作品的功能使自己的程序更加完整。

在编写过程中,当遇到问题是可以借组API文档查询,也可以XXjava吧寻求帮助等。

编写一个程序也是一个不断学习的过程,对掌握知识非常有帮助。

希望通过本次课程设计,对于进一步的java学习有深入的帮助。

 

指导教师签字:

年月日

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1