Lab 2: Improving the Crab

Table of Contents


  • Get you ready for the week's lessons.
  • Introduce you to the following concepts:
    • keyboard control
    • random numbers
    • sound
    • comments
    • dot notation
    • static methods
    • method definitions

Academic Honesty

Read the Scholastic Honesty Policy and Quest and Lab Integrity policies of the syllabus. Here are some clarifications for this particular lab:

  • This is a solo lab that you must complete individually.
  • You may discuss the code with other students for this lab.
  • You must type all the code yourself and not copy from another student.

Lab Specifications

Complete these labs before class on Tuesday 2/11/20.

Project A: Code Practice

For this lab you practice coding skillz with guided exercises.

  1. Make sure you have completed the exercises from lesson 2 as they are submitted as part of this lab.
  2. Complete the Chapter 2 exercises in CodeLab. These are review exercises and you have all the information needed to complete them. If you have questions, please contact the instructor for help.

Project B: More Sophisticated Programming

For this lab you continue developing a game by following instructions in the textbook. We will then use this process during class to continue working on your first original game.

  1. Scan the textbook chapter 3 to get an overview of the material.

    It is important to have access to the book. If you have ordered the book but have not received it yet, then you can read chapter 3 online.

  2. Complete the in-chapter exercises 3.1 through 3.24 that are listed throughout chapter 3. Exercise 3.25 is optional.

    Continue with your little-crab from Lab 1. If you have a problem completing a step and need to check your work, look at the files from Ch. 2-4 of the Book scenarios.

  3. Follow the exercise steps exactly and read the textbook as you progress through the chapter to enhance your understanding.

    For those exercises steps that have a writing or text answer, open the Scenario Information (Scenario > Scenario Information) and type the exercise number and answers at the end of the file. For example, here are my answers to the first few exercises:

    Exercises with Text Answers
    3.1: if (Greenfoot.getRandomNumber(100) < 10)
    (answers needed for 3.1, 3.2, 3.4, 3.6, 3.7, 3.20, 3.21, 3.23)
  4. Add the following to the top of the Scenario Information with the "VERSION or DATE" and "AUTHORS" fields filled in:
    PURPOSE OF PROJECT: Book tutorial chapter 3
    VERSION or DATE: 1.0  (The date completed)
    AUTHORS: Your name here
  5. When completed, zip all the files in the scenario into a single compressed folder and upload the zip file to Canvas as explained in the section of this document: Deliverables.

Lab Self-Test

Be prepared to answer questions like the following after completing this lab:

  1. What code do you write to get the following result, including the end points?
    1. A random number between 0 and 9. answer
    2. A random number between 0 and 10. answer
    3. A random number between 1 and 10. answer
    4. A random number between -10 and 10. answer
  2. To cause an actor to make a random right-turn between 0 and 45 degrees inclusive write ________.
    1. turn(random(45));
    2. turn(getRandomNumber(45));
    3. turn(Greenfoot.getRandomNumber(45));
    4. turn(Greenfoot.getRandomNumber(46));
  3. To remove an object from a scenario world, call the Actor method ________.
  4. True or false: defining a method means it will be executed.
  5. True or false: method calls always have parenthesis, even when a method does not define any parameters.
  6. True or false: defining short methods makes it easier to understand the logic of a program.
  7. To check whether a key on the keyboard has been pressed, call the Greenfoot class method ________.
  8. To play sounds, first add the sound files to the ________ folder of your scenario.
  9. To play a sound file, call the Greenfoot class method ________.

Grading Criteria

The instructor will evaluate your lab using the following criteria. Thus you should check your lab against these criteria to maximize your XP.

Lesson Exercises (from Class)

  • 2: All lesson exercises attempted and turned in
  • 1: Some lesson exercises not completed and turned in or other problems found
  • 0: No lesson exercises turned in or wrong folder name

Tutorial Lab (Textbook)

  • 4: Demonstrates mastery of the lab exercise:
    • Applies concepts from the lessons appropriately
    • Follows the steps exactly
    • Exercises perform correctly
  • 3: Has all the major functionality expected:
    • Demonstrates many techniques from the lesson
    • May deviate from the specified steps in some way
    • Implementation seems more complicated than necessary.
  • 2: Has much of the functionality expected:
    • Demonstrates some techniques from the lesson
    • Deviates from the specified steps in some way
    • Implementation seems excessively complicated.
  • 1: Serious functional problems but shows some effort and understanding:
    • Follows at least 1/2 of the of the specified steps
    • Has a major error (detected by the browser) or many minor errors
    • Demonstrates few techniques from the lesson
  • 0: Not turned in or wrong folder name

CodeLab Exercises

Number completed correctly / number exercises * 8 and rounded up to the nearest integer.

Maximum XP: 14


The CodeLab due today is submitted automatically, but other lab work must be submitted as described below.

  1. On your computer, locate the folders for the two scenarios:
    1. lesson2 (from lesson 2)
    2. little-crab (from the textbook chapter 3)
  2. Create a zip file containing both folders named and submit the zip file(s) to the Lab 2 slot of Canvas.
  3. In addition, verify you completed the the B2: Setting out boss event (quiz) in Canvas.

Please do not add any extra characters to the above folder names. Also, do not put any spaces or special characters like #, : or $ in zip file or folder names.

Your crafted code must work as submitted. Remember to test and double check your files before and after submitting them. If you make a mistake, you may resubmit up to the deadline but must resubmit all your files. For information on resubmitting see How do I change an assignment in Canvas?

Last Updated: February 10 2020 @18:24:30