Midterm 1 Review Supplements
(Arcane Studies 1)

<< Back

Instructions

  1. Complete the following handwritten on paper and make sure to put your name on your paper.
  2. Your work will be reviewed and graded, so make it presentable.
  3. The following arcane studies are due before the test starts.
  4. Review of your work by another student is required for full credit. Add the following at the top of your paper:

    Reviewed by: reviewing student's name

    Correct any problems found during the review.

Review Topics

^ top

1. Objects, instances and class diagrams

  1. Write the heading for this problem on your paper.
  2. Review section 1.3.9: Review
  3. On paper, write the question numbers and the answers for the following questions: (4m)
    1. What is an object?
    2. What is a class?
    3. How many objects can be instantiated (created) from one class?
    4. What two types of objects does a Greenfoot project have at a minimum?
    5. Does the arrow (arrow for is-a relationships) in a class diagram point towards the superclass or the subclass?
    6. Write a class signature for a public class named "Bug" that is a subclass of "Actor".
  4. Review your work with another student in the class and correct any problems.

^ top

2. Calling methods

  1. Write the heading for this problem on your paper.
  2. Review second half of section 2.4.5: Summary
  3. On your paper, create four columns with these headings:
    Question # Method name Return type Number Parameters
  4. Write the information under the above column headings for each of the following method signatures. (4m)
    1. public void play()
    2. public void addAmount(int amount)
    3. public boolean hasWings()
    4. public void compare(int x, int y, int z)
    5. public boolean isGreater(int number)
  5. Review your work with another student in the class and correct any problems.

^ top

3. Tracing if-statements

  1. Write the heading for this problem on your paper.
  2. Review the first half of section 2.3.5: Summary, 4.3.6: Alternating Images with if-else Statements, and 4.3.7: Multiple Test Conditions
  3. On your paper, for each of the following problems write the question number and a solution. (4m)
    1. The value of x after the following code executes is ________.
      int x = 7;
      if (x == 3)
      {
        x = 1;
      }
      
    2. The value of x after the following code executes is ________.
      int x = 3;
      int y = 4;
      if (x < y)
      {
        x = y;
      }
      
    3. The value of x after the following code executes is ________.
      int x = 5;
      if (x > 3)
      {
          x = x - 2;
      }
      else
      {
          x = x + 2;
      }
      
    4. The value of x after the following code executes is ________.
      int x = 1;
      if (x > 0)
      {
          x = x + 5;
      }
      else if (x > 1)
      {
          x = x + 2;
      }
      else
      {
          x = x + 7;
      }
      
  4. Review your work with another student in the class and correct any problems.

^ top

4. Coding Test Conditions

  1. Write the heading for this problem on your paper.
  2. Review lesson 3.2.3: Relational Operators and 2.2.5: Actor Movement Methods
  3. On paper, write the question numbers and the first line of an if- statement that tests for the following conditions. Assume the if-statement code is placed inside an actor. (4m)
    1. an actor is at the edge of the world
    2. an actor's x-coordinate is not equal to 42
    3. an actor is greater than 25 pixels from the left edge of the screen
    4. an actor is greater than or equal to 25 pixels from the top edge of the screen
    5. an actor is at the bottom edge of a 400 pixel high screen
  4. Review your work with another student in the class and correct any problems.

^ top

5. Variables and Assignment

  1. Write the heading for this problem on your paper.
  2. Review lesson 2.4.1: Introduction to Variables, 3.1.5: (Variable) Summary, 4.3.4: Instance Variables (Fields), and 4.3.5: Constructors and Reference Variables
  3. On your paper, write the problem number (1a, 1b, ..., 2a, ..., 3) and a solution to the following problems: (8m)
    1. Declare a local variable for storing each of the following types of data and assign a value to each variable:
      1. Money (dollars and cents)
      2. The count of the number of people in a room
      3. A single letter
      4. Whether or not an actor is at the edge of the world
      5. A GreenfootImage variable

      Add a comment after each of statement of the above indicating which are a primitive variable and which are a reference variable.

    2. On your paper, repeat the variable declarations as instance variables using the problem numbers 2a, 2b, ... 2e.
    3. Write the value of a and b on your paper after the following code snippet executes
      int a = 10;
      int b = 20;
      a = b;
      
      a is ________ b is ________
  4. Review your work with another student in the class and correct any problems.

Test Yourself (Optional)

  1. The problem with the following code snippet is ________.
    int value;
    value = 1.23;
    
    1. The "value" variable is never initialized.
    2. The data type for the "value" variable is not specified.
    3. The "value" variable is never assigned a value.
    4. The "value" variable is assigned a decimal value, but it can store only a whole number value.
  2. In a game purchasing system, the cost of a game is required. The data type that should be used to store this value is a single ________.
    1. int
    2. boolean
    3. double
    4. char
  3. We want to keep score in a game using whole numbers. The data type that should be used to store this value is a single ________.
    1. int
    2. boolean
    3. double
    4. char

^ top

6. Defining Methods

  1. Write the heading for this problem on your paper.
  2. Review lesson 3.4.5: (Method) Summary.
  3. On your paper, write the question numbers and a solution to the following problems. (5m)
    1. For the following method identify these parts:
      1. access modifier: ________
      2. return type: ________
      3. method name: ________
      4. parameter list: ________
      public void lookForFlower()
      {
          if (isTouching(Flower.class))
          {
              removeTouching(Flower.class);
          }
      }
      
    2. Write a public method named randomMove that takes one parameter named speed, moves the actor speed amount and randomly decides to turn a random amount. The method returns nothing.
    3. Write a public method named add that takes two parameters, sums the parameters and returns the sum as a type double.
  4. Review your work with another student in the class and correct any problems.

^ top

7. Constructors

  1. Write the heading for this problem on your paper.
  2. Review lesson 4.2.5: (World Constructor) Summary, 4.3.5: Constructors and Reference Variables
  3. On paper, write the question numbers and the answers for the following questions: (4m)
    1. For an actor subclass named Bug, write a constructor signature with no parameters.
    2. for an world subclass class named WildWorld, write a constructor signature with no parameters.
    3. The name of the class that contains this code is _____.
      private Dog dog;
      private Rabbit rabbit;
      public RabitPatch() {/* statements here */}
      
  4. Review your work with another student in the class and correct any problems.

^ top

8. Counting and arithmetic (3m)

  1. Write the heading for this problem on your paper.
  2. Review lesson 4.4.4: Arithmetic
  3. On your paper, write the question number and a solution to the following problems:
    1. First operation performed in 1 + 2 * 3 / 4 % 5 is ________.
    2. The value of x after the following code executes is ________.
      double x = 9 / 4;
      
    3. The value of x after the following arithmetic expression and assignment is ________.
      double x = 1 + 2 * 3 / 4 % 5;
      
    4. Write the following math expression as Java code: a + b all over 2
  4. Review your work with another student in the class and correct any problems.

Test Yourself (Optional)

  1. Of the following, the one that is NOT a complete statement for adding 1 to numAnts is ________.
    1. numAnts + 1;
    2. numAnts = numAnts + 1;
    3. numAnts = 1 + numAnts;
    4. numAnts = numAnts + 1 / 1;

^ top

<< Back