Lab 3: Finishing the Crab

Table of Contents


  • Get you ready for the week's lessons.
  • Introduce you to the following concepts:
    • constructors
    • constructing objects with new
    • primitive types vs. object types (references)
    • GreenfootImage variables
    • Instance fields (variables)
    • Variable lifetime
    • if-else statements

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/18/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 3 as they are submitted as part of this lab.
  2. Complete the Chapter 3 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: Finishing the Crab

  1. Scan the textbook chapter 4 to get an overview of the material.
  2. Complete the in-chapter exercises 4.1 through 4.26 that are listed throughout chapter 4. Exercise 4.27 is optional.

    Continue with your little-crab from Lab 2. Follow the exercise steps exactly and read the textbook as you progress through the chapter to enhance your understanding. 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. Exercises 4.1 through 4.9 do not directly apply to the scenario. For those exercises, create an Actor subclass named Exercises and add the variable declarations to the Exercises class to ensure your variable declarations compile.
    1. If you declare the variables as object variables (outside a method), put the word private in front of the variables.
    2. Exercise 4.5 will not compile because there is no Control class or Button class. Comment out this declaration.
    3. Exercise 4.6 needs a written text answer; see specification 6 below.
    4. Exercise 4.7 needs you to substitute the names sons and daughters for n1 and n2 in the example just above it. Also you need to use children instead of sum.
    5. Exercise 4.9 is a little tricky. You will need a third variable to complete the swap. Feel free to Google java swap values. Use the following print statement to verify the swap:
      System.out.println("x=" + x + " y=" + y);
  4. For those exercises steps that have a text answer, open the Scenario Information (Scenario > Scenario Information) and type the exercise number and answer at the end of the file. For example, here are my answers to the first few exercises:

    Exercises with Text Answers
    4.6: Variable has wrong data type
    (answers needed for 4.6, 4.15, 4.16, 4.17)

    Only the chapter 4 questions and answers are needed in the Scenario information.

  5. 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 4
    VERSION or DATE: 1.0  Date Completed
    AUTHORS: Your Name
  6. When completed, upload all the files in the scenario to Canvas as explained in the section of this document: Deliverables.

People working together
Image source

Project C: Pair Programming Worksheet

Pair programming is where two programmers work together at one computer to develop code projects. One, the driver, writes code while the other, the observer or navigator,[1] reviews each line of code as it is typed in. The two programmers switch roles frequently [1]. Students generally have higher confidence in their work and perform better when pair programming [2]. These effects were tested at Cabrillo College among other places [3].

Programming can be beneficial, but following certain guidelines is important to maximize success [4][5]. This project introduces you to the concepts and best practices of pair programming for our course programming projects.

Project Specifications
  1. Watch the video Introduction to Pair Programming, a professionally developed video (10 minutes).
  2. Save this Pair Programming Worksheet following the menu File > Download as > Plain Text (.txt), and save the file as pairprogramming.txt.
  3. Fill out and answer the questions in pairprogramming.txt without deleting any of the existing text.

    Provide thoughtful answers for full credit.

  4. Submit the pairprogramming.txt file with the rest of the assignment as described in Deliverables.
  5. For reference, here is a link to the The Rules of Pair Programming
References and More Information
  1. Pair programming: Wikipedia article
  2. The effects of pair-programming on performance in an introductory programming course.
  3. Pair Programming (Case Study 1)
  4. The Rules of Pair Programming
  5. All I Really Need to Know about Pair Programming I Learned in Kindergarten: Good suggestions on how to program in pairs.

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

Pair Programming Worksheet

  • 4: Student completed and submitted the learning worksheet with masterful effort
  • 3: Student completed and submitted the learning worksheet with substantial effort
  • 2: Student completed and submitted the learning worksheet with minimal effort
  • 1: Student submitted the learning worksheet
  • 0: No learning worksheet submitted

CodeLab Exercises

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

Maximum XP: 18


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 and the project C file:
    1. lesson3 (from lesson 3)
    2. little-crab (from the textbook chapter 4)
    3. pairprogramming.txt
  2. Create a zip file named containing both folders and pairprogramming.txt. Submit the zip file(s) to the Lab 3 slot of Canvas.
  3. In addition, verify you completed the the B3: Random choices 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:23