Overview

Having had our first exposure to the basics of Java programming, we’ll now turn our attention to building our programming skills. In this reading you’ll learn about the Turtle class and some of its capabilities (also known as methods). Following your reading and our class discussion, you should feel comfortable creating turtles (and the worlds they live in) and moving them around the screen in various ways.

Required Reading

Sections 3.1-3.4 (pp. 38-50) from the course textbook.

Learning Objectives

BASIC Learning Objectives

Each student will be responsible for learning and demonstrating proficiency in the following objectives PRIOR to the class meeting. The reading quiz will test these objectives.

  1. Given an object reference and a method, write a Java expression to invoke that method on the object (i.e. send a message to an object asking it to do something).
  2. Write a line of code that creates a World (or Turtle) object.
  3. Write a line of code that makes the turtle move in one of the following ways: move forward a given number of steps, turn left or right by a given angle.
  4. Identify the location of a given coordinate, (x,y), in a turtle’s World.

ADVANCED Learning Objectives

The following objectives should be mastered by each student DURING and FOLLOWING the class session through active work and practice.

  1. Describe how “=” is different in Java than it is in math.
  2. Track a turtle’s movement by reading and tracing code.

Pre-class Exercises

These exercises are geared towards mastering the BASIC learning objectives listed above. You are expected to submit them before class and it is highly recommended that you complete them before attempting the reading quiz.

  1. Textbook Problem: 3.3

  2. Write Java code to create one world object and two turtle objects. The first turtle should start in the default location (the center of the world) while the second should start at the coordinates (25, 75).

    Your answer should contain the code you entered into the Interactions Pane and either a screenshot or a drawing ofa box showing the world then put dots where the turtles will be when they start.

  3. Assume you have the following Java code:

    String s = "Hello!";

    The String class has a method named length that gives us the number of characters in the string. The length method doesn’t have any parameters. Write an expression that invokes the length method. Hint: This should be pretty similar to invoking the turnLeft method on a turtle object.