java项目工作汇报ppt模板
- 格式:ppt
- 大小:3.26 MB
- 文档页数:20
竭诚为您提供优质文档/双击可除java项目工作汇报ppt篇一:20xx813068jaVa实验8报告.ppt集美大学计算机工程学院实验报告课程名称:丁跃潮指导教师:丁跃潮实验项目名称:实验8实验项目编号:8一、目的本次实验所涉及并要求掌握的知识点。
线程,接口,继承,二、实验内容两个警察抓一个小偷三、设计和编码实现四个线程,分别为警察1,警察2,小偷,电脑,调用run()方法,记录警察1,警察2,小偷在每秒所处位置,当警察与小偷相遇时,玩家胜并结束程序,如果玩家无法在500秒内,完成抓捕任务时,玩家失败,游戏结束。
使用继承thread类来实现;importjava.util.concurrent.*;publicclasscatchstealer1extendsthread/继承thread/{police3polic1=newpolice3();police4polic2=newpolice4 ();stealer1stealr=newstealer1();threadpolice1=newth read(polic1);/设计三个线程/threadpolice2=newthread(polic2);threadstealer=newt hread(stealr);privateintxpol1;privateintxpol2;priva teintxstea;privateintypol1;privateintypol2;班级:软件1012姓名:蔡荣杰学号:20xx813068组号:实验成绩:上机实践日期:上机实践时间:学时publiccatchstealer1(){}publicvoidrun(){try{while(tr ue)timeunit.seconds.sleep(1);/同步记录警察1,警察2,小偷的位置/xpol1=polic1.getxlong();ypol1=polic1.getylong();xp ol2=polic2.getxlong();ypol2=polic2.getylong();xstea =stealr.getxlong();ystea=stealr.getylong();if(((xstea==xpol1)system.exit(0);{}police1.setdaemon(true);police1.start();police 2.setdaemon(true);police2.start();stealer.setdaemon (true);stealer.start();throwsexception}}catch(interruptedexceptione){system.out.print ln("sleep()interrupted");}/抛出异常/publicstaticvoidmain(string[]args){}catchstealer1j k=newcatchstealer1();/设计电脑线程/jk.setdaemon(true);/设为后台/jk.start();timeunit.seconds.sleep(500);system.out. println("游戏失败!");throwsexception使用实现Runnable接口来实现;代码解析与catchstealer1相似importjava.util.concurrent.*;publicclasscatchstealerextendsthread{police3polic1=newpolice3();police4polic2=newpolice4 ();stealer1stealr=newstealer1();threadpolice1=newth read(polic1);threadpolice2=newthread(polic2);thread stealer=newthread(stealr);privateintxpol1;privatein txpol2;privateintxstea;privateintypol1;privateintyp ol2;publiccatchstealer(){}publicvoidrun(){try{while(tru e)timeunit.seconds.sleep(1);xpol1=polic1.getxlong() ;ypol1=polic1.getylong();xpol2=polic2.getxlong();yp ol2=polic2.getylong();xstea=stealr.getxlong();ystea=stealr.getylong();if(((xstea==xpol1)system.exit(0);{}police1.setdaemon(true);police1.start();police 2.setdaemon(true);police2.start();stealer.setdaemon (true);stealer.start();throwsexception}}catch(interruptedexceptione){}system.out.prin tln("sleep()interrupted");publicstaticvoidmain(stri ng[]args){}catchstealerjk=newcatchstealer();jk.setd aemon(true);jk.start();timeunit.seconds.sleep(100); system.out.println("游戏失败!");throwsexception 设计警察1实现Runnable接口速度为200importjava.util.concurrent.*;importjavax.swing.joptionpane;publicclasspolice1implementsRunnable{privatefinalintcarnumber=200;stringyourchoose="";pr ivateintnorth=1;privateintsouth=2;privateintwest=3;privateinteast=4;privateintsleeptime=1;privatestati cintxlong=0;privatestaticintylong=0;publicintgetxlo ng(){篇二:javaweb项目答辩jsp项目答辩问题1.什么是b/s、c/s答案:c/s结构:client/server(客户端/服务器),桌面安装应用程序(qq、斗地主、msn)。