Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Assignment 1 added

Assignment 1 added
  • Loading branch information...
commit 7a4a05f82284787d5e6a8b4aa26e8093f0d34f90 1 parent a6e5ca7
simyseng authored
Showing with 388 additions and 0 deletions.
  1. BIN  Assignment 1/.DS_Store
  2. +7 −0 Assignment 1/.classpath
  3. +17 −0 Assignment 1/.project
  4. +67 −0 Assignment 1/.settings/org.eclipse.jdt.core.prefs
  5. BIN  Assignment 1/07-assignment-1.pdf
  6. BIN  Assignment 1/CheckerboardKarel.class
  7. +90 −0 Assignment 1/CheckerboardKarel.java
  8. BIN  Assignment 1/CollectNewspaperKarel.class
  9. +44 −0 Assignment 1/CollectNewspaperKarel.java
  10. BIN  Assignment 1/MidpointFindingKarel.class
  11. +51 −0 Assignment 1/MidpointFindingKarel.java
  12. BIN  Assignment 1/StoneMasonKarel.class
  13. +76 −0 Assignment 1/StoneMasonKarel.java
  14. BIN  Assignment 1/acm.jar
  15. BIN  Assignment 1/karel.jar
  16. +1 −0  Assignment 1/worlds/1x8.w
  17. +1 −0  Assignment 1/worlds/40x40.w
  18. +4 −0 Assignment 1/worlds/5x3.w
  19. +1 −0  Assignment 1/worlds/6x5.w
  20. +1 −0  Assignment 1/worlds/7x7.w
  21. +1 −0  Assignment 1/worlds/8x1.w
  22. +1 −0  Assignment 1/worlds/8x8.w
  23. +1 −0  Assignment 1/worlds/CheckerboardKarel.w
  24. +16 −0 Assignment 1/worlds/CollectNewspaperKarel.w
  25. +1 −0  Assignment 1/worlds/MidpointFindingKarel.w
  26. +1 −0  Assignment 1/worlds/SampleQuad1.w
  27. +1 −0  Assignment 1/worlds/SampleQuad2.w
  28. +1 −0  Assignment 1/worlds/StoneMasonKarel.w
  29. +5 −0 Assignment 1/worlds/Test.w
BIN  Assignment 1/.DS_Store
View
Binary file not shown
7 Assignment 1/.classpath
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="karel.jar"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
17 Assignment 1/.project
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Assignment1</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
67 Assignment 1/.settings/org.eclipse.jdt.core.prefs
View
@@ -0,0 +1,67 @@
+#Fri Oct 01 11:23:39 PDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
BIN  Assignment 1/07-assignment-1.pdf
View
Binary file not shown
BIN  Assignment 1/CheckerboardKarel.class
View
Binary file not shown
90 Assignment 1/CheckerboardKarel.java
View
@@ -0,0 +1,90 @@
+/*
+ * File: CheckerboardKarel.java
+ * ----------------------------
+ * When you finish writing it, the CheckerboardKarel class should draw
+ * a checkerboard using beepers, as described in Assignment 1. You
+ * should make sure that your program works for all of the sample
+ * worlds supplied in the starter folder.
+ */
+
+import stanford.karel.*;
+
+public class CheckerboardKarel extends SuperKarel {
+
+ public void run() {
+ while (leftIsClear()) {
+ fillStreet();
+ ascendToNextStreet();
+ }
+ if(leftIsBlocked()) {
+ fillStreet();
+ }
+ }
+ /*
+ * Next street available is already checked in run()
+ */
+ private void ascendToNextStreet() {
+ turnLeft();
+ move();
+ turnRight();
+ }
+
+ private void fillStreet() {
+ turnRight();
+ /*
+ * Move to last street to check whether is even or odd street.
+ * Presence of beeper at first avenue means last street was odd
+ */
+ if(frontIsClear()) {
+ move();
+ turnAround();
+ if(beepersPresent()) {
+ move();
+ turnRight();
+ fillEvenStreet();
+ }
+ else {
+ move();
+ turnRight();
+ fillOddStreet();
+ }
+ }
+ else {
+ turnLeft();
+ fillOddStreet(); // fill first street
+ }
+ goToFirstAvenue();
+ }
+ /*
+ * Set Karel to go back to 1st avenue facing East
+ */
+ private void goToFirstAvenue() {
+ turnAround();
+ while(frontIsClear()) {
+ move();
+ }
+ turnAround();
+ }
+
+ private void fillOddStreet() {
+ putBeeper();
+ while(frontIsClear()) {
+ move();
+ if(frontIsClear()) {
+ move();
+ putBeeper();
+ }
+ }
+
+ }
+ private void fillEvenStreet() {
+ while(frontIsClear()) {
+ move();
+ putBeeper();
+ if(frontIsClear()) {
+ move();
+ }
+ }
+ }
+
+}
BIN  Assignment 1/CollectNewspaperKarel.class
View
Binary file not shown
44 Assignment 1/CollectNewspaperKarel.java
View
@@ -0,0 +1,44 @@
+/*
+ * File: CollectNewspaperKarel.java
+ * --------------------------------
+ * At present, the CollectNewspaperKarel subclass does 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.
+ */
+
+import stanford.karel.*;
+
+public class CollectNewspaperKarel extends SuperKarel {
+
+ public void run() {
+ moveToDoorStreet();
+ moveToPickBeeper();
+ returnToStart();
+ }
+
+ private void moveToDoorStreet() {
+ turnRight();
+ move();
+ turnLeft();
+ }
+
+ private void moveToPickBeeper() {
+ while (noBeepersPresent()) {
+ move();
+ }
+ pickBeeper();
+ }
+
+ private void returnToStart() {
+ turnAround();
+ while (frontIsClear()) {
+ move();
+ }
+ turnRight();
+ move();
+ turnRight();
+ }
+
+}
BIN  Assignment 1/MidpointFindingKarel.class
View
Binary file not shown
51 Assignment 1/MidpointFindingKarel.java
View
@@ -0,0 +1,51 @@
+/*
+ * File: MidpointFindingKarel.java
+ * -------------------------------
+ * When you finish writing it, the MidpointFindingKarel class should
+ * leave a beeper on the corner closest to the center of 1st Street
+ * (or either of the two central corners if 1st Street has an even
+ * number of corners). Karel can put down additional beepers as it
+ * looks for the midpoint, but must pick them up again 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.
+ */
+
+import stanford.karel.*;
+
+public class MidpointFindingKarel extends SuperKarel {
+
+ public void run()
+ {
+ fillStreet();
+ turnAround();
+ move();
+ while(beepersPresent()) {
+ removeLastBeeper();
+ move();
+ }
+ putMidBeeper();
+ }
+
+ private void putMidBeeper() {
+ turnAround();
+ move();
+ putBeeper();
+ }
+ private void removeLastBeeper() {
+ while(beepersPresent()) {
+ move();
+ }
+ turnAround();
+ move();
+ pickBeeper();
+ }
+
+ private void fillStreet() {
+ move();
+ while(frontIsClear()) {
+ putBeeper();
+ move();
+ }
+ }
+
+}
BIN  Assignment 1/StoneMasonKarel.class
View
Binary file not shown
76 Assignment 1/StoneMasonKarel.java
View
@@ -0,0 +1,76 @@
+/*
+ * File: StoneMasonKarel.java
+ * --------------------------
+ * The StoneMasonKarel subclass as it appears here does nothing.
+ * When you finish writing it, it should solve the "repair the quad"
+ * problem from Assignment 1. In addition to editing the program,
+ * you should be sure to edit this comment so that it no longer
+ * indicates that the program does nothing.
+ */
+
+import stanford.karel.*;
+
+public class StoneMasonKarel extends SuperKarel {
+
+ public void run()
+ {
+ repairColumn();
+ while (frontIsClear()) {
+ moveToNextColumn();
+ repairColumn();
+ }
+ }
+
+ /*
+ * Assuming that all columns are 4 avenues apart
+ */
+ private void moveToNextColumn() {
+ move();
+ move();
+ move();
+ move();
+ }
+
+ /*
+ * Pre-condition: Robot is facing east along street 1
+ * Post-condition: Ronot is facing east along street 1
+ */
+ private void repairColumn() {
+ turnLeft();
+ workOnColumn();
+ descendColumn();
+ turnLeft();
+ }
+
+ /*
+ * Pre-condition: Robot facing north
+ * Post-condition: Robot facing south
+ * Robot moves down after completed repairing column
+ */
+ private void descendColumn() {
+ turnAround();
+ while (frontIsClear()) {
+ move();
+ }
+ }
+
+ /*
+ * Robot already facing north. Will drop beeper if
+ * no beeper is present at corner
+ */
+ private void workOnColumn() {
+ while (frontIsClear()) {
+ if (noBeepersPresent()) {
+ putBeeper();
+ }
+ move();
+ }
+ /*
+ * Work on highest street below column
+ */
+ if (noBeepersPresent()) {
+ putBeeper();
+ }
+ }
+
+}
BIN  Assignment 1/acm.jar
View
Binary file not shown
BIN  Assignment 1/karel.jar
View
Binary file not shown
1  Assignment 1/worlds/1x8.w
View
@@ -0,0 +1 @@
+Dimension: (1, 8)
1  Assignment 1/worlds/40x40.w
View
@@ -0,0 +1 @@
+Dimension: (40, 40)
4 Assignment 1/worlds/5x3.w
View
@@ -0,0 +1,4 @@
+Dimension: (5, 3)
+Karel: (1, 1) east
+BeeperBag: INFINITE
+Speed: 0.75
1  Assignment 1/worlds/6x5.w
View
@@ -0,0 +1 @@
+Dimension: (6, 5)
1  Assignment 1/worlds/7x7.w
View
@@ -0,0 +1 @@
+Dimension: (7, 7)
1  Assignment 1/worlds/8x1.w
View
@@ -0,0 +1 @@
+Dimension: (8, 1)
1  Assignment 1/worlds/8x8.w
View
@@ -0,0 +1 @@
+Dimension: (8, 8)
1  Assignment 1/worlds/CheckerboardKarel.w
View
@@ -0,0 +1 @@
+Dimension: (8, 8)
16 Assignment 1/worlds/CollectNewspaperKarel.w
View
@@ -0,0 +1,16 @@
+Dimension: (7, 5)
+Wall: (3, 2) west
+Wall: (3, 2) south
+Wall: (3, 3) west
+Wall: (3, 4) west
+Wall: (3, 5) south
+Wall: (4, 2) south
+Wall: (4, 5) south
+Wall: (5, 2) south
+Wall: (5, 5) south
+Wall: (6, 2) west
+Wall: (6, 4) west
+Beeper: (6, 3) 1
+Karel: (3, 4) east
+BeeperBag: INFINITE
+Speed: 0.00
1  Assignment 1/worlds/MidpointFindingKarel.w
View
@@ -0,0 +1 @@
+Dimension: (9, 9)
1  Assignment 1/worlds/SampleQuad1.w
View
@@ -0,0 +1 @@
+Dimension: (13, 13)
1  Assignment 1/worlds/SampleQuad2.w
View
@@ -0,0 +1 @@
+Dimension: (13, 9)
1  Assignment 1/worlds/StoneMasonKarel.w
View
@@ -0,0 +1 @@
+Dimension: (13, 13)
5 Assignment 1/worlds/Test.w
View
@@ -0,0 +1,5 @@
+Dimension: (10, 10)
+Beeper: (5, 5) 10
+Karel: (5, 5) east
+BeeperBag: INFINITE
+Speed: 0.00
Please sign in to comment.
Something went wrong with that request. Please try again.