下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、斯坦福大学公开课:编程方法学ASSIGNMENTS这个是根据Assig nment #1: Email and Karel the RobotKarel problems due: 1:15pm on Friday, April 12th ,2013自己写的代码,没有做过优化,这次的作业中Problem3的代码有问题,只能实现在大多数的世界中使用,在1XN这种会失效还没有修改,刚接触这门课程,还是挺有趣的,卡雷尔 机器人程序。我先声明了一个通用的类,然后再做的作业public class 通用 extends SuperKarelpublic void moveBackToWall()turn
2、Aro un d();while(fro ntlsClear()move();public void moveToWall()while(fro ntlsClear()move();public void moveBackward()turnAro un d();move();turnAro un d();public void turn Back()turnLeft();turnLeft();problem"/* File: CollectNewspaperKarel.java* At present, the CollectNewspaperKarel subclass does
3、 nothing.* Your job in the assignment is to add the necessary code to* instruct Karel to walk to the door of its house, pick up the* newspaper (represented by a beeper, of course), and then return* to its initial position in the upper left corner of the house.*/ public class CollectNewspaperKarel ex
4、tendsl用 public void run() moveToWall(); turnRight();move();turnLeft();move();pickBeeper();turnBack();move();turnRight();moveToWall();turnLeft(); moveToWall();putBeeper();turnBack();problem2public class UnitedNationsKarel extends 通用 public void run()while(fro ntlsClear()if(beepersPrese nt()pickBeeper
5、();buildHouse();if(fron tlsClear()move();private void buildHouse()getReady();build();fin ish();private void getReady()moveBackward();turnLeft();private void fini sh()turnLeft();private void build()buildPart();nextToWork();buildPart();getNext();buildPart();private void buildPart()putBeeper();move();p
6、utBeeper();move();putBeeper();private void n extToWork()move();turnRight();move();turnRight();private void getNext()turnAro un d(); nextToWork(); problem3/* * File: CheckerboardKarel.java * When you finish writing it, theCheckerboardKarel class should draw * a checkerboard using beepers, as describe
7、d in Assignment 1. You * should make sure that your program works for all of the sample * worlds supplied in the starter folder. */ public class CheckerboardKarel extends 通 用 public voidrun() while(leftlsClear() while(frontlsClear() putRow(); moveToNextStreet(); while(f rontlsClear() putRow(); check
8、Beeper(); privatevoidputRow() putBeeper(); if(frontIsClear() move(); if(frontIsClear() move(); private void moveToNextStreet() checkBeeper(); moveBackToWall(); moveForPutRow(); private voidcheckBeeper() moveBackward(); if(beepersPresent() else move(); putBeeper(); priva tevoidmoveForPutRow() turnRig
9、ht(); if(beepersPresent() move(); turnRight(); move(); else move(); turnRight(); problem4/* File: Midpoi ntFi ndi ngKarel.java* When you finish writing it, the MidpointFindingKarel class should* leave a beeper on the corner closest to the cen ter of 1st Street* (or either of the two cen tral corners
10、 if 1st Street has an even* nu mber of corn ers).Karel can put dow n additi onal beepers as it* looks for the midpo int, but must pick them up aga in before it* stops. The world may be of any size, but you are allowed to* assume that it is at least as tall as it is wide.*/ public class MidpointFindingKarel extends 通用 public void run()fullOfBeepers();while(beepersPrese nt()cha ngeForTake();take On eBeeper();turnAro un d();move();private void fullOfBeepers()putBeeper();while(fro ntlsClear()move();putBeeper();private void cha ngeForTake()moveToWall();turnAro un d();private void t
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 养鸟兽医聘用协议书
- 2026-2031中国轨道交通设备行业市场竞争格局报告
- 科技企业的股权激励模式分析
- 2025年高处安装、维护、拆除考试试题(含答案)
- 起重吊装作业安全预防措施及应急预案
- 浙教版八年级上册5.5 一次函数的简单应用教案
- 公共场所心脏骤停应急预案演练脚本
- 职场心理健康干预机制设计
- 车间火灾事故应急预案演练脚本
- 2026年彩钢板房防火涂料施工合同
- 2025年导游资格证考试题库及答案
- 基于多尺度建模的AZ31镁合金固态增材制造机理与性能优化研究
- 2025年大学《新能源科学与工程-太阳能利用技术》考试参考题库及答案解析
- xx乡供水工程可行性研究报告
- 全国大学生职业规划大赛《计算机科学与技术》专业生涯发展展示【曾获省级一等奖】
- 饭店股权责任合同范本
- 2025中铝招标有限公司面向集团内部公开招聘2人(北京)笔试历年参考题库附带答案详解
- 2025年社区工作者考试试题(完整版)及答案
- 2025北师大版三年级数学上册全册教案
- 辽宁农商银行2026年校园招聘笔试考试参考试题及答案解析
- 商贸公司质量管理流程手册
评论
0/150
提交评论