Computer Science @ Marlboro  

Introduction to Programming with LEGO® Robotics

Info | Lecture Notes | Assignments | Syllabus | Resources | Roster

  Learn to program in Java. Teach Lego robots various stunts. Study the fundamental notions behind computer programming, such as abstraction, modularity, data structures, syntax, and procedures. Play with Legos some more.
  • When: Tu/Fri 1:30-2:50, Fall 2002
  • Where: Sci 217
  • Faculty: Jim Mahoney
  • Text: Java Programming from the Beginning by K. N. King.
  • Credits: 4 ( 9 hours/week outside class )
  • Prereq: none

Lecture Notes

  1. for Fri Sep 6
    • Read chapter 1 in King's book.
    • Send me ( some email telling me that you're taking the class, and how comfortable you are with computers, including whether you own a computer, and if so what kind and what programs you typically run on it, as well as which of the following sound easy and which sound hard:
      • Visit the web page
      • Find Sun's Java website with an internet search engine.
      • Create a text file on your computer or a lab computer.
      • Get to the command prompt, and rename the text file.
      • Transfer the text file to your computer account on akbar, which is the computer with your email account, using a file transfer program like sftp.

  2. for Fri Sep 13
    • Read In the Beginning was the Command Line
    • Read through chapter 2 in the text
    • Make sure that you can
      • Create a java text file with a legal java program, like the program or any in the text.
      • Get to the command line, in the directory where that file lives.
      • Compile and run the file.
      • Put in some errors to see what kinds of errors you get.
      You can do this either on akbar (ssh to get there), or on your own computer (after installing JDK and an editor like XEmacs and setting your PATH appropriately).
    • In the text, do exercises 6 and 10 on pg 80 of the text.
    • Write a program that asks for the radius of a circle, and then prints the area of the circle. (The formula is Area=Pi*radius*radius where Pi=3.14159...) Feel free to base it on the file I showed in class. How accurate is the answer? And is there a way to do "radius squared"? How do you find that out? (You'll want to use the SimpleIO and Convert classes by the textbook author for this one. Follow his instructions in the appendix for downloading them. You can also find them on our website, along with my code on akbar in http::akbar/~mahoney/cs/courses/fall02/javacode/jpb/ right near http::akbar/~mahoney/cs/courses/fall02/javacode/
    • If all this doesn't get finished by Friday's class, bring in your questions to class and we'll see where you all are.

  3. for the week of Fri Sep 20
    • Read chapter 3 in King's book, on Classes and Objects
    • Do chapter 3, exercise 2, 5 on page 123.
    • Do programming project 3 on page 125 of the text. That is, type in the Fraction class as described in section 3.8 of the text, into a file Add the methods that the problem requests. Then create another file, that creates some Fraction objects and tests them.
    • Optional: Add the Fraction methods described in problem 4 on page 125. (This will lead you into some of the behavior of the Java String class.)

  4. for the week of Fri Sep 27
    • Reading assignments only. Class time used to work on first lego robot project, due next week. (You need to get started on this now.)
    • Learn about Lego Java OS (LeJOS) by reading this tutorial.
    • Optional: start reading chapter 4 in King's book, on Conditionals.

  5. for the week of Fri Oct 4
    • Build a lego vehicle with two motors, one of which runs wheels or treads on either side. (Optional: Attach a bumper with a touch sensor on the front.)
    • Write a LeJOS program which moves the vehicle in a rough square, and download and run it on your Lego robot. Your program should make the robot
      1. First, beep twice.
      2. Then do these steps four times:
        • Go forward.
        • Turn right by about 90 degrees.
      3. Stop all the motors.
      4. Finally, beep three times.
    • Email me the java code and a description of your vehicle.
    • Optional #1: use the digital camera to document your vehicle. Create a web page describing your first project and code.
    • Optional #2: (After you can use an "if" statement.) attach a touch sensor to the front of your robot. Write a program which goes forward until the robot bumps into something, and then turns away from the wall when it does.

  6. for Fri Oct 11
    • Read chapter 4 in our text, on conditionals ("if" and "while") and boolean logic
    • Do exercises 6, 11, and 21 on pages 174-176.
    • Do programming projects 9 (wind speed) and 11 (fibonnaci numbers) on page 178. Email me your .java files.

  7. for Fri Oct 25
    • Add either a light sensor or a bumper to your earlier lego robot. Write some LeJOS java code that has it do something interesting - you've seen examples of following a black/white border, and changing direction when it bumps into something. We'll use Fri Oct 18 class time to work on these.

  8. for Fri Nov 1
    • Read chapter 5, on arrays. Also check out section 13.1, on page 542 and following.
    • Do Exercise 5, 9, and 11 on pages 215 and 216.
    • Do Programming Project 6, on page 217.
    • Look at the program. Adopt the code so that the X's make some winning moves. Add a lpoop which tests to see if one player has won.

  9. for Fri Nov 8
    • Read chapters 6 and 7, which cover graphics and class (i.e. static) methods in Java.
    • Submit a proposal for a final project.
    • On page 292 and the following, do exercises 3, 7, 17, and 21.
    • Do one of the following two programming projects:
      • number 7 on page 295 - adding numbers given on the command line, or
      • number 5 on page 252 - the checkerboard.

  10. for Tues Nov 19
    • Pick one of your Lego robot earlier programming projects, one that has more than one file. Convert part of into a package, and add some documentation. See LegoNotesNov12.html.

  11. for Tues Nov 26
    • Read chapter 11 in the text, on Subclasses and inheritance.
    • Do either one of the the following two things:
      1. Do exercise 4 on page 479 of the text, a Person and Employee class, and exercise 10(c) on page 480.
      2. Do programming project 2 on pg 481, add a Triangle class to the NervousShapes program. (You'll need to download and be able to run the files in javacode/nov22 which I showed in class.)

Syllabus (tentative, as of 9/1/02)
 Sep 6:     chap 1, Computer Basics
 Sep 10,13: chap 2 part 1, writing and debugging a Java program
 Sep 17,20: chap 2 part 2, and introduce Lego/LeJOS classes  (project 1 assign)
 Sep 24,27: chap 3 classes and objects using LeJOS examples
 Oct 1,4:   chap 4 control structures
 Oct 8,11:  digression into LeJOS examples      -- project 1 due -- 
 Oct 15,17: chap 5 arrays    (skip chapter 6)   -- midterm --
 Oct 25:    chap 7 more classes, using LeJOS examples (enough time?)
 Oct 28,1:  chap 8 more flow control
 Nov 5,8:   chap 9 primitive types (really needed?) (term project assign)
 Nov 12,14: chap 10 more on classes, continue LeJOS examples and work
 Nov 19,22: chap 11 subclasses and inheritance
 Nov 26:    chap 14 files
 Dec 2-6:   open time for term project work
 Dec 10     open time for term project work


Jim Mahoney (
Last modified: Tue Nov 26 02:28:04 EST 2002
LEGO® is a trademark of the LEGO Group of companies, which does not sponsor, authorize or endorse this site. We use the LEGO Mindstorms Robots as a tool to teach computer science, but we don't design, build, or sell the product.