斯坦福大学公开课编程方法学ASSIGNMENT_第1页
斯坦福大学公开课编程方法学ASSIGNMENT_第2页
斯坦福大学公开课编程方法学ASSIGNMENT_第3页
免费预览已结束,剩余2页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论