java课程设计报告(模拟电梯系统)
JAVA模拟电梯

1.import javax.swing.*;2.import java.awt.*;3.import java.util.*;4.public class Hufan extends JFrame{5.static HuPanel hp;6.public static void main(String[] args) {7.new Hufan();8.}9.public Hufan(){10.hp=new HuPanel();11.this.add(hp);12.this.setTitle("模拟电梯");13.this.setSize(350, 650);14.this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);15.this.setVisible(true);16.}17.}18.class HuPanel extends JPanel{19.DianTi dt;20.Person ps;21.public HuPanel(){22.init();23.dt=new DianTi(45, 0);24.//启动电梯线程25.Thread t=new Thread(dt);26.t.start();27.}28.public DianTi getDianTi(){29.return dt;30.}31.public Person getPerson(){32.return ps;33.}34.public void init(){35.Random r=new Random();36.int i=r.nextInt(4)+1;37.switch(i){38.case 1:39.ps=new Person(350,500,0,1);40.break;41.case 2:42.ps=new Person(350,350,0,2);43.break;44.case 3:45.ps=new Person(350,200,0,3);46.break;47.case 4:48.ps=new Person(350,50,0,4);49.break;50.}51.Thread t=new Thread(ps);52.t.start();53.}54.public void paint(Graphics g){55.super.paint(g);56.//画楼梯与楼层57.g.fillRect(30, 0, 6, 600);58.g.fillRect(200, 0, 6, 600);59.g.fillRect(200, 150, 330, 6);60.g.fillRect(200, 300, 330, 6);61.g.fillRect(200, 450, 330, 6);62.g.fillRect(30, 600, 500, 6);63.//画电梯64.g.setColor(Color.gray);65.g.fillRect(dt.x, dt.y, 150, 150);66.//画人67.g.setColor(Color.red);68.g.fillRect(ps.x, ps.y, 50, 100);69.//画要上几楼70.g.setColor(Color.black);71.g.setFont(new Font("宋体",Font.BOLD,17));72.if(ps.endFloor!=0&&ps.direct==0){73.g.drawString("去"+ps.endFloor+"楼", ps.x, ps.y+20);74.}75.//画我走了76.if(ps.direct==1){77.g.drawString("我走了", ps.x, ps.y+20);78.}79.}80.81.}82.class Person implements Runnable{83.int x;84.int y;85.int direct;86.int startFloor;87.int endFloor;88.int speed=5;89.boolean isStop=true;90.boolean isDead=true;91.DianTi dt;92.public Person(int x,int y,int direct,int startFloor){93.this.x=x;94.this.y=y;95.this.direct=direct;96.this.startFloor=startFloor;97.}98.//得到目的楼99.public void getEndF(){100.endFloor=new Random().nextInt(4)+1;101.}102.@Override103.public void run() {104.// TODO Auto-generated method stub105.//得到ps106.dt=Hufan.hp.dt;107.while(isDead){108.if(isStop){109.if(direct==0){110.x-=speed;111.if(x==200){112.while(true){113.this.getEndF();114.//如果目的楼和自己等,重新得到endFloor 115.if(startFloor==endFloor){116.this.getEndF();117.}else{118.break;119.}120.}121.//到了电梯,这时让电梯到自己在的楼层122.dt.topDown=startFloor;123.//启动电梯124.dt.isStop=true;125.//人停止126.isStop=false;127.}128.}else if(direct==1){129.x+=speed;130.//如果到边界。
电梯模拟程序课程设计

电梯模拟程序课程设计一、课程目标知识目标:1. 让学生理解电梯的工作原理,掌握电梯运行的模拟编程知识。
2. 使学生掌握利用流程图描述电梯运行逻辑的方法。
3. 帮助学生理解并运用条件语句和循环语句实现电梯模拟程序。
技能目标:1. 培养学生运用编程语言(如Scratch或Python)编写简单电梯模拟程序的能力。
2. 培养学生通过流程图分析问题、解决问题的能力。
3. 提高学生团队协作、沟通交流的能力。
情感态度价值观目标:1. 培养学生对编程的兴趣,激发学生主动探索新知识的热情。
2. 培养学生严谨、细心的学习态度,增强面对困难的勇气和毅力。
3. 培养学生遵守程序设计规范,养成良好的编程习惯。
课程性质:本课程为信息技术学科的课程,以项目式学习为主,注重实践操作和团队合作。
学生特点:学生为五年级学生,具备一定的信息技术基础,对新事物充满好奇,喜欢动手操作。
教学要求:教师需引导学生通过自主探究、小组合作等方式完成课程内容,注重培养学生的实践能力和创新精神。
同时,关注学生的个体差异,提供有针对性的指导。
通过本课程的学习,使学生能够达到上述课程目标,实现具体的学习成果。
二、教学内容1. 电梯工作原理介绍:包括电梯的基本结构、运行原理、信号控制系统等,让学生对电梯的运行机制有整体认识。
2. 编程语言基础:回顾并巩固Scratch或Python编程语言的基础知识,如变量、列表、条件语句、循环语句等,为编写电梯模拟程序打下基础。
3. 流程图设计:学习如何利用流程图描述电梯运行的逻辑过程,分析电梯运行中的各种情况,并进行流程图设计。
4. 电梯模拟程序编写:根据流程图,运用所学编程知识,分组合作编写电梯模拟程序,实现基本的运行、停止、开门、关门等功能。
5. 程序调试与优化:指导学生如何调试程序,发现并解决程序中的问题,提高程序的稳定性和运行效率。
教学内容安排和进度:第一课时:电梯工作原理介绍,回顾编程语言基础知识。
第二课时:学习流程图设计,分析电梯运行逻辑。
电梯模拟程序(Java语言编写)

import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;public class LiftMainTest{public static void main(String args[]){new LiftTest("电梯测试");}}//批量数据测试对话框class Dialog extends JDialog implements ActionListener {int Message=0;JPanel DJPanel=new JPanel();JTextField TestField[]=new JTextField[16];JLabel TestLabel1=new JLabel("时间");JLabel TestLabel2=new JLabel("人数");JLabel TestLabel3=new JLabel("起始楼层");JLabel TestLabel4=new JLabel("目标楼层");JButton ok=new JButton("确定");JButton cancel=new JButton("取消");Dialog(JFrame f,String s,boolean b){super(f,s,b);DJPanel.setLayout(new GridLayout(7,3));for(int i=0;i<=15;i++){TestField[i]=new JTextField(4);}DJPanel.add(TestLabel1);DJPanel.add(TestLabel2);DJPanel.add(TestLabel3);DJPanel.add(TestLabel4);DJPanel.add(TestField[0]);DJPanel.add(TestField[1]);DJPanel.add(TestField[2]);DJPanel.add(TestField[3]);DJPanel.add(TestField[4]);DJPanel.add(TestField[5]);DJPanel.add(TestField[6]);DJPanel.add(TestField[7]);DJPanel.add(TestField[8]);DJPanel.add(TestField[9]);DJPanel.add(TestField[10]);DJPanel.add(TestField[11]);DJPanel.add(TestField[12]);DJPanel.add(TestField[13]);DJPanel.add(TestField[14]);DJPanel.add(TestField[15]);DJPanel.add(ok);DJPanel.add(cancel);add(DJPanel);ok.addActionListener(this);cancel.addActionListener(this);setBounds(450,170,300,300);}public void actionPerformed(ActionEvent e)//Dialog监听函数{if(e.getSource()==ok){Message=1;setVisible(false);}else if(e.getSource()==cancel){Message=-1;setVisible(false);}else{;}}}//LiftTest类class LiftTest extends JFrame implements ActionListener {Dialog mydialog;JMenuBar menubar;JMenu menu,submenu,submenuhelp;JMenuItem item1,item2,menuitemhelp;//变量定义int x;int y;int LIsRun=0;//左电梯是否在运行(0或1)int RIsRun=0;//右电梯是否在运行(0或1)int LDirection=0;//左电梯运行方向int RDirection=0;//右电梯运行方向int LWantLevel=0;//乘客目的层数int RWantLevel=0;int LNowLevel=0;//乘客开始时所在层数int RNowLevel=0;int LLiftNowLevel=1;//左电梯目前所在层数int RLiftNowLevel=1;//右电梯目前所在层数int WantDirection=0;//乘客目标运行方向int WaitPeopleNum[]=new int[11];//保留数组(未用)int a=0;int b=0;//线程定义LIO lio=new LIO();RIO rio=new RIO();Thread LStartThread=new Thread(lio);Thread RStartThread=new Thread(rio);//上下电梯的按钮定义JButton Blue10=new JButton(new ImageIcon("10x.gif"));JButton Blue9=new JButton(new ImageIcon("9x.gif"));JButton Blue8=new JButton(new ImageIcon("8x.gif"));JButton Blue7=new JButton(new ImageIcon("7x.gif"));JButton Blue6=new JButton(new ImageIcon("6x.gif"));JButton Blue5=new JButton(new ImageIcon("5x.gif"));JButton Blue4=new JButton(new ImageIcon("4x.gif"));JButton Blue3=new JButton(new ImageIcon("3x.gif"));JButton Blue2=new JButton(new ImageIcon("2x.gif"));JButton Red9=new JButton(new ImageIcon("9s.gif"));JButton Red8=new JButton(new ImageIcon("8s.gif"));JButton Red7=new JButton(new ImageIcon("7s.gif"));JButton Red6=new JButton(new ImageIcon("6s.gif"));JButton Red5=new JButton(new ImageIcon("5s.gif"));JButton Red4=new JButton(new ImageIcon("4s.gif"));JButton Red3=new JButton(new ImageIcon("3s.gif"));JButton Red2=new JButton(new ImageIcon("2s.gif"));JButton Red1=new JButton(new ImageIcon("1s.gif"));//电梯门定义JButton LLiftLDoor=new JButton(new ImageIcon("LLiftLDoor.gif"));//设置门图标JButton LLiftRDoor=new JButton(new ImageIcon("LLiftRDoor.gif"));//设置门图标JButton RLiftLDoor=new JButton(new ImageIcon("RLiftLDoor.gif"));//设置门图标JButton RLiftRDoor=new JButton(new ImageIcon("RLiftRDoor.gif"));//设置门图标//电梯内部按钮定义JButton LPressButton1=new JButton("1");JButton LPressButton2=new JButton("2");JButton LPressButton3=new JButton("3");JButton LPressButton4=new JButton("4");JButton LPressButton5=new JButton("5");JButton LPressButton6=new JButton("6");JButton LPressButton7=new JButton("7");JButton LPressButton8=new JButton("8");JButton LPressButton9=new JButton("9");JButton LPressButton10=new JButton("10");JButton RPressButton1=new JButton("1");JButton RPressButton2=new JButton("2");JButton RPressButton3=new JButton("3");JButton RPressButton4=new JButton("4");JButton RPressButton5=new JButton("5");JButton RPressButton6=new JButton("6");JButton RPressButton7=new JButton("7");JButton RPressButton8=new JButton("8");JButton RPressButton9=new JButton("9");JButton RPressButton10=new JButton("10");量数据测试”按钮的Panel //组件定义JLabel LL=new JLabel("当前电梯内部人数:");JLabel RL=new JLabel("当前电梯内部人数:");JButton Start=new JButton("开始电梯调度模拟");//开始电梯调度模拟按钮JButton Test=new JButton("开始批量数据测试");//开始批量数据测试按钮JTextArea LTextArea=new JTextArea(5,5);JTextArea RTextArea=new JTextArea(5,5);//电梯调度函数Cal(LIsRun,LLiftNowLevel,q,LDirection)int Cal(int x,int y,int z,int w){return(x*(y-z)*w);}//方法函数LiftTest(String s){super(s);setSize(1000,600);setLocation(100,50);//Dialogmydialog=new Dialog(this,"批量数据测试",true);//菜单项设置menubar=new JMenuBar();menu=new JMenu("菜单");submenu=new JMenu("联系作者");submenuhelp=new JMenu("帮助");item1=new JMenuItem("程序简介");item2=new JMenuItem("源代码");menu.add(item1);menu.addSeparator();menu.add(item2);menu.addSeparator();menu.add(submenu);menu.addSeparator();menu.add(submenuhelp);submenu.add(new JMenuItem("作者简介"));submenuhelp.add(new JMenuItem("使用帮助"));menubar.add(menu);setJMenuBar(menubar);//面板布局管理器设置WindowsPanel.setLayout(new GridLayout(1,6)); WaitPeopleNumPanel.setLayout(new GridLayout(10,1)); LeftPanel.setLayout(new GridLayout(3,1));RightPanel.setLayout(new GridLayout(3,1));LeftLiftPanel.setLayout(null);//左电梯运动轨道Panel布局管理器设为空RightLiftPanel.setLayout(null);//右电梯运动轨道Panel布局管理器设为空UpDownButtonPanel.setLayout(new GridLayout(10,2)); LButtonPanel.setLayout(new GridLayout(4,3));RButtonPanel.setLayout(new GridLayout(4,3));LeftLiftPanel.setBackground(Color.green);RightLiftPanel.setBackground(Color.green); UpDownButtonPanel.setBackground(Color.yellow); UpMainPanel.setLayout(new GridLayout(1,2));LBoxPanel.setLayout(null);//左电梯箱Panel布局管理器设为空RBoxPanel.setLayout(null);//右电梯箱Panel布局管理器设为空//电梯箱设置LBoxPanel.setSize(165,51);RBoxPanel.setSize(165,51);LBoxPanel.setLocation(0,459);RBoxPanel.setLocation(0,459);LeftLiftPanel.add(LBoxPanel);RightLiftPanel.add(RBoxPanel);//电梯门设置LLiftLDoor.setEnabled(false);LLiftRDoor.setEnabled(false);RLiftLDoor.setEnabled(false);RLiftRDoor.setEnabled(false);LLiftLDoor.setSize(82,51);LLiftRDoor.setSize(82,51);RLiftLDoor.setSize(82,51);RLiftRDoor.setSize(82,51);LLiftLDoor.setLocation(0,0);LLiftRDoor.setLocation(82,0);RLiftLDoor.setLocation(0,0);RLiftRDoor.setLocation(82,0);LBoxPanel.add(LLiftLDoor);LBoxPanel.add(LLiftRDoor);RBoxPanel.add(RLiftLDoor);RBoxPanel.add(RLiftRDoor);//分别添加两个电梯的10个按钮LButtonPanel.add(LPressButton1);//左电梯LButtonPanel.add(LPressButton2); LButtonPanel.add(LPressButton3); LButtonPanel.add(LPressButton4); LButtonPanel.add(LPressButton5); LButtonPanel.add(LPressButton6); LButtonPanel.add(LPressButton7); LButtonPanel.add(LPressButton8); LButtonPanel.add(LPressButton9); LButtonPanel.add(LPressButton10); RButtonPanel.add(RPressButton1);//右电梯RButtonPanel.add(RPressButton2); RButtonPanel.add(RPressButton3); RButtonPanel.add(RPressButton4); RButtonPanel.add(RPressButton5); RButtonPanel.add(RPressButton6); RButtonPanel.add(RPressButton7); RButtonPanel.add(RPressButton8); RButtonPanel.add(RPressButton9); RButtonPanel.add(RPressButton10);//添加上下电梯按钮至UpDownButtonPanel面板JButton Unabled1=new JButton();Unabled1.setEnabled(false);JButton Unabled2=new JButton();Unabled2.setEnabled(false); UpDownButtonPanel.add(Unabled1);//开始第一个空着UpDownButtonPanel.add(Blue10); UpDownButtonPanel.add(Red9); UpDownButtonPanel.add(Blue9); UpDownButtonPanel.add(Red8); UpDownButtonPanel.add(Blue8);UpDownButtonPanel.add(Red7); UpDownButtonPanel.add(Blue7); UpDownButtonPanel.add(Red6); UpDownButtonPanel.add(Blue6); UpDownButtonPanel.add(Red5); UpDownButtonPanel.add(Blue5); UpDownButtonPanel.add(Red4); UpDownButtonPanel.add(Blue4); UpDownButtonPanel.add(Red3); UpDownButtonPanel.add(Blue3); UpDownButtonPanel.add(Red2); UpDownButtonPanel.add(Blue2); UpDownButtonPanel.add(Red1); UpDownButtonPanel.add(Unabled2);//最后一个空着//等待人数文本框定义JTextField Text10=new JTextField(" 10楼等待人数:",8); Text10.setEditable(false);JTextField Text9=new JTextField(" 9楼等待人数:",8); Text9.setEditable(false);JTextField Text8=new JTextField(" 8楼等待人数:",8); Text8.setEditable(false);JTextField Text7=new JTextField(" 7楼等待人数:",8); Text7.setEditable(false);JTextField Text6=new JTextField(" 6楼等待人数:",8); Text6.setEditable(false);JTextField Text5=new JTextField(" 5楼等待人数:",8); Text5.setEditable(false);JTextField Text4=new JTextField(" 4楼等待人数:",8); Text4.setEditable(false);JTextField Text3=new JTextField(" 3楼等待人数:",8); Text3.setEditable(false);JTextField Text2=new JTextField(" 2楼等待人数:",8); Text2.setEditable(false);JTextField Text1=new JTextField(" 1楼等待人数:",8); Text1.setEditable(false);//向UpMainPanel中添加组件UpMainPanel.add(Start);UpMainPanel.add(Test);//添加等待人数文本框至WaitPeopleNumPanel面板WaitPeopleNumPanel.add(Text10); WaitPeopleNumPanel.add(Text9); WaitPeopleNumPanel.add(Text8); WaitPeopleNumPanel.add(Text7); WaitPeopleNumPanel.add(Text6);WaitPeopleNumPanel.add(Text5);WaitPeopleNumPanel.add(Text4);WaitPeopleNumPanel.add(Text3);WaitPeopleNumPanel.add(Text2);WaitPeopleNumPanel.add(Text1);//分别向LeftPanel(左电梯提示器),RightPanel(右电梯提示器)添加相应组件LeftPanel.add(LButtonPanel);LeftPanel.add(LL);LeftPanel.add(LTextArea);RightPanel.add(RButtonPanel);RightPanel.add(RL);RightPanel.add(RTextArea);//添加至总面板WindowsPanel.add(WaitPeopleNumPanel);WindowsPanel.add(LeftPanel);WindowsPanel.add(LeftLiftPanel);WindowsPanel.add(UpDownButtonPanel);WindowsPanel.add(RightLiftPanel);WindowsPanel.add(RightPanel);//添加监听器Start.addActionListener(this);Test.addActionListener(this);Blue10.addActionListener(this);Blue9.addActionListener(this);Blue8.addActionListener(this);Blue7.addActionListener(this);Blue6.addActionListener(this);Blue5.addActionListener(this);Blue4.addActionListener(this);Blue3.addActionListener(this);Blue2.addActionListener(this);Red9.addActionListener(this);Red8.addActionListener(this);Red7.addActionListener(this);Red6.addActionListener(this);Red5.addActionListener(this);Red4.addActionListener(this);Red3.addActionListener(this);Red2.addActionListener(this);Red1.addActionListener(this);Monitor mon=new Monitor();//新建监听器对象LPressButton1.addActionListener(mon);LPressButton2.addActionListener(mon);LPressButton3.addActionListener(mon);LPressButton4.addActionListener(mon);LPressButton5.addActionListener(mon);LPressButton6.addActionListener(mon);LPressButton7.addActionListener(mon);LPressButton8.addActionListener(mon);LPressButton9.addActionListener(mon);LPressButton10.addActionListener(mon);RPressButton1.addActionListener(mon);RPressButton2.addActionListener(mon);RPressButton3.addActionListener(mon);RPressButton4.addActionListener(mon);RPressButton5.addActionListener(mon);RPressButton6.addActionListener(mon);RPressButton7.addActionListener(mon);RPressButton8.addActionListener(mon);RPressButton9.addActionListener(mon);RPressButton10.addActionListener(mon);//添加至窗口add(WindowsPanel,BorderLayout.CENTER);//主窗体添加至中间add(UpMainPanel,BorderLayout.NORTH);//UpMainPanel添加至北面setVisible(true);//Frame默认是不可见的,所有Panel都是默认可见的validate();//设置组件可见setResizable(false);//设置整个窗体是不可调整大小的setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//右上角“叉号”关闭按钮响应函数}//Runnable接口函数定义class LIO implements Runnable//左电梯接口函数{public void run(){while(true){try{Thread.sleep(5);}//避免CPU使用率达到100%catch(InterruptedException a){}while(LNowLevel!=0){int q=x;if(Cal(LIsRun,LLiftNowLevel,q,LDirection)<=Cal(RIsRun,RLiftNowLevel,q, RDirection))//左电梯近{LNowLevel=0;if(LLiftNowLevel<=q){for(int i=LLiftNowLevel;i<q;i++){LBoxPanel.setLocation(0,(459-i*51));LTextArea.append("妹妹\n");RTextArea.append("哥哥\n");LLiftNowLevel=i;LIsRun=1;LDirection=1;if(LNowLevel!=0&&i==(LNowLevel-1)&&LDirection==1&&WantDirecti on==1)//停留等待4秒{for(int v=1;v<=82;v++)//开门{try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((-v),0);LLiftRDoor.setLocation((82+v),0);}try{Thread.sleep(4000);}catch(InterruptedException a){}for(int v=1;v<=82;v++)//关门{try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((v-82),0);LLiftRDoor.setLocation((163-v),0);}}try{Thread.sleep(1000);}catch(InterruptedException a){}}}else{for(int i=LLiftNowLevel;i>q;i--){LBoxPanel.setLocation(0,(459-(i-2)*51));LTextArea.append("妹妹");RTextArea.append("哥哥");LLiftNowLevel=i;LIsRun=1;LDirection=-1;if(LNowLevel!=0&&i==(LNowLevel+1)&&LDirection==-1&&WantDirection= =-1)//停留等待4秒{for(int v=1;v<=82;v++)//开门{try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((-v),0);LLiftRDoor.setLocation((82+v),0);}try{Thread.sleep(4000);}catch(InterruptedException a){}for(int v=1;v<=82;v++)//关门{try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((v-82),0);LLiftRDoor.setLocation((163-v),0);}}try{Thread.sleep(1000);}catch(InterruptedException a){}}}LIsRun=0;LDirection=0;LLiftNowLevel=q;}else{break;}for(int e=1;e<=82;e++)//开门{if(a==1)//识别用户按下电梯箱内小按钮{x=LWantLevel;LNowLevel=LWantLevel;a=0;//"a"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((-e),0);LLiftRDoor.setLocation((82+e),0);}for(int e=1;e<=82;e++){if(a==1)//识别用户按下电梯箱内小按钮{x=LWantLevel;LNowLevel=LWantLevel;a=0;//"a"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}}for(int e=1;e<=82;e++)//关门{if(a==1)//识别用户按下电梯箱内小按钮{x=LWantLevel;LNowLevel=LWantLevel;a=0;//"a"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}LLiftLDoor.setLocation((e-82),0);LLiftRDoor.setLocation((163-e),0);}}}}}class RIO implements Runnable//右电梯接口函数{public void run(){while(true){try{Thread.sleep(5);}catch(InterruptedException a){}while(RNowLevel!=0){int p=y;if(Cal(LIsRun,LLiftNowLevel,p,LDirection)>=Cal(RIsRun,RLiftNowLevel,p,RDir ection))//右电梯近{RNowLevel=0;if(RLiftNowLevel<=p){for(int i=RLiftNowLevel;i<p;i++){RBoxPanel.setLocation(0,(459-i*51));LTextArea.append("妹妹\n");RTextArea.append("哥哥\n");RLiftNowLevel=i;RIsRun=1;RDirection=1;if(RNowLevel!=0&&i==(RNowLevel-1)&&RDirection==1&&WantDirec tion==1)//停留等待4秒{for(int v=1;v<=82;v++){try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((-v),0);RLiftRDoor.setLocation((82+v),0);}try{Thread.sleep(4000);}catch(InterruptedException a){}for(int v=1;v<=82;v++){try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((v-82),0);RLiftRDoor.setLocation((163-v),0);}}try{Thread.sleep(1000);}catch(InterruptedException a){}}}else{for(int i=RLiftNowLevel;i>p;i--){RBoxPanel.setLocation(0,(459-(i-2)*51));LTextArea.append("妹妹");RTextArea.append("哥哥");RLiftNowLevel=i;RIsRun=1;RDirection=-1;if(RNowLevel!=0&&i==(RNowLevel+1)&&RDirection==-1&&WantDirection ==-1)//停留等待4秒{for(int v=1;v<=82;v++){try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((-v),0);RLiftRDoor.setLocation((82+v),0);}try{Thread.sleep(4000);}catch(InterruptedException a){}for(int v=1;v<=82;v++){try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((v-82),0);RLiftRDoor.setLocation((163-v),0);}}try{Thread.sleep(1000);}catch(InterruptedException a){}}}RIsRun=0;RDirection=0;RLiftNowLevel=p;}else{break;}for(int e=1;e<=82;e++){if(b==1)//识别用户按下电梯箱内小按钮{y=RWantLevel;RNowLevel=RWantLevel;b=0;//"b"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((-e),0);RLiftRDoor.setLocation((82+e),0);}for(int e=1;e<=82;e++)if(b==1)//识别用户按下电梯箱内小按钮{y=RWantLevel;RNowLevel=RWantLevel;b=0;//"b"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}}for(int e=1;e<=82;e++){if(b==1)//识别用户按下电梯箱内小按钮{y=RWantLevel;RNowLevel=RWantLevel;b=0;//"b"值复位}try{Thread.sleep(49);}catch(InterruptedException a){}RLiftLDoor.setLocation((e-82),0);RLiftRDoor.setLocation((163-e),0);}}}}}//"开始"按钮和"上下键"接口函数public void actionPerformed(ActionEvent e){if(e.getSource()==Start){LStartThread.start();RStartThread.start();}else if(e.getSource()==Test){mydialog.setVisible(true);}else if(e.getSource()==Red1){LNowLevel=1;RNowLevel=1;x=1;y=1;WantDirection=1; }else if(e.getSource()==Red2)LNowLevel=2;RNowLevel=2;x=2;y=2;WantDirection=1;}else if(e.getSource()==Red3){LNowLevel=3;RNowLevel=3;x=3;y=3;WantDirection=1;}else if(e.getSource()==Red4){LNowLevel=4;RNowLevel=4;x=4;y=4;WantDirection=1;}else if(e.getSource()==Red5){LNowLevel=5;RNowLevel=5;x=5;y=5;WantDirection=1;}else if(e.getSource()==Red6){LNowLevel=6;RNowLevel=6;x=6;y=6;WantDirection=1;}else if(e.getSource()==Red7){LNowLevel=7;RNowLevel=7;x=7;y=7;WantDirection=1;}else if(e.getSource()==Red8){LNowLevel=8;RNowLevel=8;x=8;y=8;WantDirection=1;}else if(e.getSource()==Red9){LNowLevel=9;RNowLevel=9;x=9;y=9;WantDirection=1;}else if(e.getSource()==Blue10){LNowLevel=10;RNowLevel=10;x=10;y=10;WantDirection=-1; }else if(e.getSource()==Blue9){LNowLevel=9;RNowLevel=9;x=9;y=9;WantDirection=-1;}else if(e.getSource()==Blue8){LNowLevel=8;RNowLevel=8;x=8;y=8;WantDirection=-1;}else if(e.getSource()==Blue7)LNowLevel=7;RNowLevel=7;x=7;y=7;WantDirection=-1; }else if(e.getSource()==Blue6){LNowLevel=6;RNowLevel=6;x=6;y=6;WantDirection=-1; }else if(e.getSource()==Blue5){LNowLevel=5;RNowLevel=5;x=5;y=5;WantDirection=-1; }else if(e.getSource()==Blue4){LNowLevel=4;RNowLevel=4;x=4;y=4;WantDirection=-1; }else if(e.getSource()==Blue3){LNowLevel=3;RNowLevel=3;x=3;y=3;WantDirection=-1; }else if(e.getSource()==Blue2){LNowLevel=2;RNowLevel=2;x=2;y=2;WantDirection=-1; }else{;}}//左右电梯电梯箱内小按钮监听器class Monitor implements ActionListener{public void actionPerformed(ActionEvent e){if(e.getSource()==LPressButton1){LWantLevel=1;a=1;}else if(e.getSource()==LPressButton2){LWantLevel=2;a=1;}else if(e.getSource()==LPressButton3){LWantLevel=3;a=1;else if(e.getSource()==LPressButton4) {LWantLevel=4;a=1;}else if(e.getSource()==LPressButton5) {LWantLevel=5;a=1;}else if(e.getSource()==LPressButton6) {LWantLevel=6;a=1;}else if(e.getSource()==LPressButton7) {LWantLevel=7;a=1;}else if(e.getSource()==LPressButton8) {LWantLevel=8;a=1;}else if(e.getSource()==LPressButton9) {LWantLevel=9;a=1;}else if(e.getSource()==LPressButton10) {LWantLevel=10;a=1;}else if(e.getSource()==RPressButton1) {RWantLevel=1;b=1;}else if(e.getSource()==RPressButton2) {RWantLevel=2;b=1;}else if(e.getSource()==RPressButton3) {RWantLevel=3;b=1;}else if(e.getSource()==RPressButton4) {RWantLevel=4;b=1;else if(e.getSource()==RPressButton5){RWantLevel=5;b=1;}else if(e.getSource()==RPressButton6){RWantLevel=6;b=1;}else if(e.getSource()==RPressButton7){RWantLevel=7;b=1;}else if(e.getSource()==RPressButton8){RWantLevel=8;b=1;}else if(e.getSource()==RPressButton9){RWantLevel=9;b=1;}else if(e.getSource()==RPressButton10){RWantLevel=10;b=1;}else{;}}}}/*//////////////////////////////////////////////////////////////////////////////////文件说明:程序用java语言编写,自行安装JDK(下载网址:)。
模拟电梯问题实验报告

电梯模拟问题一、目的与要求1. 掌握线性结构的逻辑特点及存储实现;2. 根据选题,按规范化流程完成课程设计报告:⑴.提供需求分析。
(15分)⑵.列出概要设计。
(包括:抽象数据类型的描述;程序结构图或功能模块图)(20分)⑶.给出详细设计。
(包括:①存储结构的描述;②算法的详细设计,对复杂算法,最好画出其N-S流程图;③函数的调用关系图)(30分)⑷.进行调试分析(注:调试时遇到的问题及解决方法,程序的输出结果及对结果的分析)。
(15分)⑸. 整理设计总结。
(设计心得体会,以及其他总结信息等)(10分)⑹.附有程序清单(注:代码可具有适当注释,用来说明程序的功能、结构)。
(10分)二、设计步骤1、线性结构是有序数据元素的集合,存在着“一对一”的线性关系且只有一个首结点,一个尾结点,首结点只有后继没有前趋,尾结点只有前趋没有后继。
顺序表的存储结构包括顺序表和链表,顺序存储是指将线性表元素按照逻辑顺序依次存储在一组连续的地址单元中。
链式存储是通过结点中的链域将线性表中n个结点按其逻辑顺序链接在一起。
分为:单向链表,双向链表,循环链表。
2、(1)设计一个电梯模拟系统。
这是一个离散的模拟程序,因为电梯系统是乘客和电梯等“活动体”够成的集合,虽然他们彼此交互作用,但是他们的行为是基本独立的。
在离散的模拟中,一模拟时钟决定每个活动体的动作发生的时刻和顺序,系统在某个模拟瞬间处理有待完成的各种事情,然后把模拟时钟推进到某个动作预定要发生的下一个时刻。
可模拟某校五层教学楼的电梯系统,或者九层教学楼的电梯系统。
此程序的关键是模拟好电梯运行状态的转换与乘客进出的同步进行,需要一个函数判断电梯的运行状态,决定电梯的下一个运行状态如电梯的开门,关门,上升,下降,减速,加速等,也需要模拟时钟的函数来判断该运行哪个函数,也需要定义几个结构体存放结点信息。
(2)时钟函数:void DoTime(){//此函数用于模拟时钟while(1){if(Time>MaxTime)return;TestPeople();//两个始终都会被调用的函数Controler();struct Activity* p=activity.next;if(p==NULL){Time=MaxTime;}if(p&&Time>=p->time){//取出活动队头的,检测定时是否到了activity.next=p->next;p->fn();free(p);}Time++;}}其中activity是关键,它是一个链表在链表的头部是计时器时间最小的函数,根据模拟时钟判断是否调用这个函数以及删除这个节点。
电梯控制系统(Java课程设计)内容

(1)新的请求插入到上行队列头。
(2)电梯到达某个楼层将这个楼层的请求从上行队列的队列头删除,后继的更高楼层号成为对列头。
当电梯正在下行时,如果下行队列的队列头改变时,系统将同时将这个新的队列头发送给电梯作为它的新目的地。有两种原因引起下行队列头的改变。
(2)M被插入到上行队列的合适位置。
(3)如果M被插到上行队列头。
如果电梯正处于上行状态。将M发送给电梯作为目的地。
如果电梯处于停止状态。将M发送给电梯作为目的地。
(4)电梯到达此楼层。
(5)电梯自动打开门(用例9)。
(6)乘客进入电梯。
(7)超重测试(用例6)。
用例2按下某楼层的下行按钮(go down stair)。
用例8打开某层电梯锁(open floor)
此层的楼层请求按钮和电梯内的楼层按钮恢复正常。
用例9自动打开电梯门(auto open door)
(1)电梯到达某楼层。
(2)电梯自动开门。
用例10自动关闭电梯门(auto close door)
(1)电梯门打开的状态达到设置的时限。
(2)关闭电梯门。
A3 类模型
根据分析,我们可以得到下面这些类。
乘客类(Passenger)、管理员类(Manager)、电梯类(Elevator)、电梯门类(ElevatorDoor)、楼层的上行请求按钮类(Go Up Request)、楼层的下请求按钮类(Gequest)、楼层锁类(lock)、指示灯类(Indicate Light)、队列类(Queue)、定时器类(Timer)、异常处理类(Expection)。
电梯模拟课程设计

课程设计实验报告课程名称__数据结构__题目名称电梯模拟专业班级学号学生姓名指导教师_2011 年1 月日一、需求分析及实现提示[需求分析](1)、模拟某校五层教学楼的电梯系统。
该楼有一个自动电梯,能在每层停留。
五个楼层由下至上依次称为地下层、第一层、第二层、第三层和第四层,其中第一层是大楼的进出层,即是电梯的“本垒层”,电梯“空闲”时,将来该层候命。
(2)、乘客可随机地进出于任何层。
对每个人来说,他有一个能容忍的最长等待时间,一旦等候电梯时间过长,他将放弃。
(3)、模拟时钟从0开始,时间单位为0.1秒。
人和电梯的各种动作均要耗费一定的时间单位(简记为t):有人进出时,电梯每隔40t测试一次,若无人进出,则关门关门和开门各需要20t每个人进出电梯均需要25t如果电梯在某层静止时间超过300t,则驶回1层候命。
(4)、按时序显示系统状态的变化过程:发生的全部人和电梯的动作序列。
[实现提示](1)楼层由下至上依次编号为0,1,2,3,4。
每目有要求Up(上)和Down(下)的两个按钮,对应l0个变量CallUp[0..4]和CallDown[0..4]。
电梯内5个目标层按钮对应变量CallCar[0..4]。
有人按下某个按钮时,相应的变量就置为1,一旦要求满足后,电梯就把该变量清为0。
(2)电梯处于三种状态之一:GoingUp(上行)、GoingDown(下行)和IdIe(停候)。
如果电梯处于IdIe状态且不在1层,则关门并驶回1层。
在1层停候时,电梯是闭门候命。
一旦收到往另一层的命令,就转入GoingUp或GoingDown状态,执行相应的操作。
(3)用变量Time表示模拟时钟,初值为0,时间单位(t)为0.1秒。
其他重要的变量有:Floor——电梯的当前位置(楼层);D1——值为0,除非人们正在进入和离开电梯;D2——值为0,如果电梯已经在某层停候300t以上;D3——值为0,除非电梯门正开着又无人进出电梯;State——电梯的当前状态(GoingUp,GoingDown,IdIe)。
数据结构——电梯模拟的报告

数据结构——电梯模拟的报告数据结构——电梯模拟的报告⒈引言在现代社会,电梯已经成为了人们生活中不可或缺的一部分。
电梯的运行和调度涉及到众多复杂的算法和数据结构。
为了提高电梯的运行效率和用户体验,本报告将介绍一种电梯模拟的数据结构设计。
⒉背景和目标在城市高楼大厦中,电梯的运行和调度是一个极其重要的问题。
每天数以万计的乘客需要借助电梯上下楼,所以我们需要设计一种电梯调度算法来保证乘客能够快速、方便地到达目的地。
本报告旨在介绍一种基于数据结构的电梯模拟方案,提高电梯的运行效率和用户体验。
⒊系统架构在电梯模拟系统中,主要包括以下几个部分:电梯控制器、电梯队列、乘客请求队列和电梯状态管理模块。
电梯控制器负责接收乘客的请求并将其分配给特定的电梯,电梯队列记录电梯所在楼层和运行方向,乘客请求队列保存尚未得到满足的乘客请求,电梯状态管理模块负责监控电梯的状态和运行情况。
⒋数据结构设计⑴电梯队列电梯队列使用循环数组来保存电梯所在楼层和运行方向。
每个电梯对应一个循环数组,数组中的每个元素表示一个楼层的状态,包括空闲、上升和下降。
⑵乘客请求队列乘客请求队列使用链表来保存尚未得到满足的乘客请求。
每个节点表示一个乘客请求,包括乘客所在楼层和目标楼层。
⑶电梯状态管理模块电梯状态管理模块使用状态机来管理电梯的状态和运行情况。
状态机包括电梯的空闲状态、运行状态和停止状态。
⒌算法设计⑴电梯调度算法电梯调度算法负责根据乘客的请求选择最佳的电梯响应。
常用的电梯调度算法包括最短路径算法、最佳负载均衡算法等。
⑵电梯运行算法电梯运行算法负责根据电梯的状态和所运载乘客的请求,确定电梯下一步的行动。
常用的电梯运行算法包括最近停靠楼层算法、深度优先搜索算法等。
⒍实现和测试在本章节中,将介绍电梯模拟系统的实现细节和测试方法。
主要包括编程语言的选择、具体实现算法的具体实现和性能测试。
⒎总结和展望在本章节中,将总结本文提出的电梯模拟方案的优点和不足,提出可能的改进方向,并展望未来可能的研究方向。
数据结构——电梯模拟的报告

数据结构——电梯模拟的报告数据结构——电梯模拟的报告1. 简介本文档将介绍电梯模拟的实现过程和基本原理。
通过模拟电梯的行为,我们可以更好地理解数据结构在实际应用中的作用和效果。
2. 问题描述在楼房中,电梯通常被用来运送乘客。
电梯内部有多个按钮,表示不同楼层的乘客需求。
乘客可以按下按钮来请求乘坐电梯到达特定楼层。
电梯的运行顺序应该是合理的,比如不会从高楼层下降到低楼层。
本模拟的电梯系统需要满足以下要求:- 电梯能接收来自乘客的请求。
- 电梯能根据请求的楼层,按照合理的顺序运行,将乘客送到目标楼层。
- 当电梯到达目标楼层,乘客可以进入或离开电梯。
- 电梯需要实时更新运行状态,如目标楼层、当前楼层等。
3. 数据结构设计为了实现电梯模拟,我们需要设计合适的数据结构来存储电梯的状态和乘客请求。
以下是我们设计的关键数据结构:3.1 电梯状态电梯的状态包括当前楼层、目标楼层和运行方向等信息。
我们可以使用一个结构体来表示电梯的状态:```c++struct ElevatorState {int currentFloor;int targetFloor;Direction direction;};```其中,`currentFloor`表示当前所在楼层,`targetFloor`表示目标楼层,`direction`表示电梯的运行方向。
3.2 乘客请求乘客请求包括乘客所在楼层和目标楼层。
我们可以使用一个结构体来表示乘客请求:```c++struct Request {int fromFloor;int toFloor;};```其中,`fromFloor`表示乘客所在楼层,`toFloor`表示目标楼层。
3.3 电梯控制器电梯控制器用于管理电梯的状态和乘客请求。
我们可以使用一个队列来存储乘客请求,使用一个变量来保存电梯的当前状态。
以下是电梯控制器的设计:```c++class ElevatorController {private:std::queue<Request> requests;ElevatorState state;public:void addRequest(Request request);void processRequests();};```其中,`addRequest`方法用于添加乘客请求到队列中,`processRequests`用于处理乘客请求并控制电梯的运行。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java课程设计报告组号:第四组课题名称:模拟电梯调度班级:09计一课题组成员姓名及学号:09030101课程设计日期:2011.6.20-2011.6.24地点:秋白楼B720一.正文1)[课程设计目的与要求]○1目的掌握线程的应用及线程在多媒体中的使用,了解线程的运行机制和线程的新建、就绪、运行、挂起、死亡五种状态,对线程由新的认识和巩固。
熟练java的动画编程,理解repaint()方法的调用过程及如何通过改写update()方法和双缓冲技术消除动画中出现的闪烁现象。
理解java的容器和组件的应用。
掌握java的事件处理机制:实现ActionListener接口,对事件源添加侦听器,实现actionPerformed()方法用以处理事件源所产生的事件。
另外使组员能够针对具体的有一定代表性的小型综合应用类课题设计、分析,全面掌握面向对象的思想、JAVA语言的应用技巧、方法,从而使组员进一步理解和掌握利用JAVA开发综合系统的过程,学会用java开发工具,同时培养组员的合作意识和团队精神,培养学生对实际系统的采用面向对象的方法进行分析与设计能力,从而使学生提高JAVA语言运用与开发的综合能力。
○2需求分析模拟电梯调度:有一栋三层的楼房,楼内有三个电梯。
要求电梯实现可以正常上下,和到达目的楼层后即停留并且实现开门及关门动作。
电梯需有多层停留功能即:当对同一个电梯需要其在多层都有下客时,电梯要在有下客动作的楼层停留然后自动去下一个有下客动作的楼层,而不需要乘客在次发出请求。
电梯具有距离发出请求的楼层最近的电梯响应请求的功能即:当某一楼层有乘客需要使用电梯时,由距离该楼层最近的电梯去响应,而不是任意一个电梯都可以响应。
(注:当存在距离该楼层最近的电梯且该电梯正在远离该楼层运动时该电梯不响应,当存在多个电梯距离该楼层最近时由编号低的电梯响应而不是全都响应。
2)[本人在课程设计中承担的任务]在课程设计中我主要负责事件处理,并判断该事件是何种事件,需要做出怎样的响应。
同时确定各电梯的工作状态,以及判断该事件是否应该得到响应若响应该事件那么应由哪一个电梯去响应。
当然我所做的还有判断哪一个电梯距离发出请求的楼层最近,此时由距离该楼层最近的电梯响应请求,若距离最近的电梯处于远离该楼层的运动状态时则由下一个最近的电梯响应,若存在多个电梯距离最近,那么由编号低的响应。
总的来说我的工作是考虑各种情况下给控制电梯各种动作(上、下、开门、关门、电梯响应、楼层)的变量赋予正确的值以实现电梯的正常运作。
3)[程序中使用的数据结构及符号说明]由于电梯有三个楼层也有三层,所以要实现各电梯之间互不影响就需要由不同的变量去控制电梯的动作。
这也是为什么程序中变量较多的原因。
下面是对本段程序中使用到得变量的解释说明:Object str:获取的组件信息赋予str(按钮名)。
String st:获取的组件信息赋予st(按钮上的内容)。
int a,b,c:三个临时变量,主要用于记录各电梯当前位置(y1,y2,y3)与产生请求的楼层的差值,用以判断哪一个电梯距离该楼层最近。
int y1,y2,y3:记录各电梯的位置,同时通过加1减1控制电梯的上下,y1对应第一个电梯y2对应第二个电梯y3对应第三个电梯。
int number[]:记录电梯有效信息,有4个元素(本程序中第一个元素未用),number[1]=1时说明第一个电梯响应number[2]=2时说明第二个电梯响应number[3]=3时说明第三个电梯响应。
number[]值为0时未响应即电梯未有动作。
int s:控制电梯的上下动作,s=1时电梯向上运动s=-1电梯向下运动。
int n1[],n2[],n3[]:记录各电梯中所响应的楼层信息,n1[]、n2[]、n3[]各对应一二三号电梯,且各有三个元素各对应于一二三层楼。
n1[]、n2[]、n3[]中元素值为1说明对应楼层有响应即电梯到达该楼层时要停留并开关门。
值为0说明无响应。
boolean moving1,moving2,moving3:记录电梯的状态,moving1、moving2、moving3各对应一二三号电梯。
值为true时电梯处于动作状态(上下或开关门),值为false时电梯处于静止状态。
boolean open1,open2,open3:电梯的开门关门控制变量,open1、open2、open3各控制一二三号电梯的开关门动作。
值为true时允许电梯开门,值为false时允许电梯关门。
int a1,a2,a3,b1,b2,b3,c1,c2,c3:记录各电梯响应的楼层信息,与n1[],n2[],n3[]用处差不多,但不可少。
a1、a2、a3分别对应n1[0]、n1[1]、n1[2]以此类推b,c对应n2,n3。
其主要目的是当电梯到达最后一个目的楼层后将电梯的有效信息number[]的值设置为0。
这是n1[],n2[],n3[]无法做到的,应为在到达相应的目的楼层后n1[],n2[],n3[]中的相应值也就设置为0了。
Button bt1···:各组件(各楼层及各电梯的按钮)。
4)[程序流程图]由于此程序中情况众多,因此流程图中的判断框较多也较复杂。
下面给出一个较简单的流程图。
5)[程序运行时的初值和运行结果]程序开始运行时,未点击任何按钮所以对于我的程序部分来说不存在初始值,只有y1=440,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=false,moving3=falsen1[]={0,0,0},n2[]={0,0,0},n3[]={0,0,0},number[]={0,0,0,0}此时三个电梯均处于第一层。
下面分几种情况分别说明一下程序实现的电梯调度的过程:○1.若开始时点击bt1即第一层的up按钮,则通过计算得出三个电梯均距离第一层最近,所以由一号电梯响应请求。
此时open1=true,number[1]=1随即一号电梯门打开并关上,此时点击一号电梯上的楼层按钮,比如bt5即第三层。
此时各变量值为:S=1y1=440,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=true,moving2=false,moving3=falsen1[]={0,0,1},n2[]={0,0,0},n3[]={0,0,0},number[]={0,1,0,0}随即电梯向上移动到达三楼后open1=true,number[1]=1开门并关门此时:S=1y1=140,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=false,moving3=falsen1[]={0,0,0},n2[]={0,0,0},n3[]={0,0,0},number[]={0,0,0,0}此时再点击bt1,则通过计算得出二号和三号电梯距离第一层最近,所以由二号电梯响应请求。
此时open2=true,number[2]=2随即二号电梯门打开并关上,此时点击二号电梯上的楼层按钮,比如bt24即第二层。
此时各变量值为:S=1y1=140,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=true,moving3=falsen1[]={0,0,0},n2[]={0,1,0},n3[]={0,0,0},number[]={0,0,2,0}随即电梯向上移动到达二楼后open2=true,number[2]=2开门并关门此时:S=1y1=140,y2=290,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=false,moving3=falsen1[]={0,0,0},n2[]={0,0,0},n3[]={0,0,0},number[]={0,0,0,0}此时点击bt21即第二层的up按钮,则通过计算的出二号电梯距离第二层最近,所以由二号电梯响应请求。
此时open2=true,number[2]=2随即二号电梯门打开并关上,此时点击二号电梯上的楼层按钮,比如bt25即第三层。
此时各变量值为:S=1y1=140,y2=290,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=true,moving3=falsen1[]={0,0,0},n2[]={0,0,1},n3[]={0,0,0},number[]={0,0,2,0}随即电梯向上移动到达三楼后open2=true,number[2]=2开门并关门此时:S=1y1=140,y2=140,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=false,moving3=falsen1[]={0,0,0},n2[]={0,0,0},n3[]={0,0,0},number[]={0,0,0,0}○2.若开始时点击bt1,,则通过计算得出三个电梯均距离第一层最近,所以由一号电梯响应请求。
此时open1=true,number[1]=1随即一号电梯门打开并关上,此时点击一号电梯上的楼层按钮,比如bt5即第三层。
此时各变量值为:S=1y1=440,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=true,moving2=false,moving3=falsen1[]={0,0,1},n2[]={0,0,0},n3[]={0,0,0},number[]={0,1,0,0}随即电梯开始向上移动,若在一号电梯向上移动并且过了第二层但没到第三层时点击bt21即二楼的up按钮,则经过计算得到一号电梯距离二楼最近,但是由于一号电梯正处于远离二楼的运动状态中所以一号电梯不响应请求,由二号电梯响应,此时:S=1290<y1<140,y2=440,y3=440open1=false,open2=false,open3=falsemoving1=true,moving2=true,moving3=falsen1[]={0,0,1},n2[]={0,1,0},n3[]={0,0,0},number[]={0,1,2,0}随即二号电梯向上移动,显然一号电梯比二号电梯早到达目的楼层,当一号电梯到达目的楼层时open1=true,number[1]=1,open2=false,number[2]=2,一号电梯开门并关门此时:S=1y1=140,290<y2<440,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=true,moving3=falsen1[]={0,0,0},n2[]={0,1,0},n3[]={0,0,0},number[]={0,0,2,0}当二号电梯到达目的楼层时open2=true,number[2]=2,此时二号电梯开门并关门此时:S=1y1=140,y2=290,y3=440open1=false,open2=false,open3=falsemoving1=false,moving2=false,moving3=falsen1[]={0,0,0},n2[]={0,0,0},n3[]={0,0,0},number[]={0,0,0,0}○3.若开始时点击按钮bt1,则由一号电梯响应请求此时open1=true,number[1]=1随即一号电梯门打开并关上,此时点击一号电梯上的楼层按钮,比如bt5和bt4即第三层和第二层。