(Arcane Studies 1)

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

Correct any problems found during the review.*reviewing student's name*

- 1. Objects, instances and class diagrams
- 2. Calling Methods
- 3. Tracing if-statements
- 4. Test Conditions
- 5. Variables and Assignment
- 6. Defining Methods
- 7. Constructors
- 8. Counting and Arithmetic

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

- Review your work with another student in the class and correct any problems.

- Write the heading for this problem on your paper.
- Review second half of section 2.4.5: Summary
- On your paper, create four columns with these headings:
Question # Method name Return type Number of Parameters - Write the information under the above column headings for each of the following method signatures. (4m)
`public void play()`

`public void addAmount(int amount)`

`public boolean hasWings()`

`public void compare(int x, int y, int z)`

`public boolean isGreater(int number)`

- Review your work with another student in the class and correct any problems.

`if`

-statements - Write the heading for this problem on your paper.
- Review the first half of section 2.3.5: Summary, 4.3.6: Alternating Images with if-else Statements, and 4.3.7: Multiple Alternatives
- On your paper, for each of the following problems write the question number and a solution. (4m)
- The value of x after the following code executes is ________.
int x = 7; if (x == 3) { x = 1; }

- The value of x after the following code executes is ________.
int x = 3; int y = 4; if (x < y) { x = y; }

- The value of x after the following code executes is ________.
int x = 5; if (x > 3) { x = x - 2; } else { x = x + 2; }

- 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; }

- The value of x after the following code executes is ________.
- Review your work with another student in the class and correct any problems.

- Write the heading for this problem on your paper.
- Review lesson 3.2.3: Relational Operators and 2.2.5: Actor Movement Methods
- 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)- an actor is at the edge of the world. For example
if (isAtEdge())

- an actor's
*x*-coordinate is not equal to 42 - an actor is greater than 25 pixels from the left edge of the screen
- an actor is greater than or equal to 25 pixels from the top edge of the screen
- an actor is at the bottom edge of a 400 pixel high screen

- an actor is at the edge of the world. For example
- Review your work with another student in the class and correct any problems.

- Write the heading for this problem on your paper.
- 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
- On your paper, write the problem number and a solution to each of the following problems: (8m)
- Declare a
**local variable**for storing each of the following types of data and assign a value to each variable:- Money (dollars and cents)
- The count of the number of people in a room
- A single letter
- Whether or not an actor is at the edge of the world
- 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.

- On your paper, repeat the variable declarations of problem 1 directly above as
**instance variables**and label the problem parts 2a, 2b, ... 2e. - 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 ________

- Declare a
- Review your work with another student in the class and correct any problems.

- The problem with the following code snippet is ________.
int value; value = 1.23;

- The "value" variable is never initialized.
- The data type for the "value" variable is not specified.
- The "value" variable is never assigned a value.
- The "value" variable is assigned a decimal value, but it can store only a whole number value.

- 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 ________.
`int`

`boolean`

`double`

`char`

- 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 ________.
`int`

`boolean`

`double`

`char`

- Write the heading for this problem on your paper.
- Review lesson 3.4.6: (Method) Summary.
- On your paper, write the question numbers and a solution to the following problems. (5m)
- For the following method identify these parts:
- access modifier: ________
- return type: ________
- method name: ________
- parameter list: ________

public void lookForFlower() { if (isTouching(Flower.class)) { removeTouching(Flower.class); } }

- 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. - Write a
`public`

method named`add`

that takes two parameters, sums the parameters and returns the sum as a type`double`

.

- For the following method identify these parts:
- Review your work with another student in the class and correct any problems.

- Write the heading for this problem on your paper.
- Review lesson 4.2.5: (World Constructor) Summary, 4.3.5: Constructors and Reference Variables
- On paper, write the question numbers and the answers for the following questions: (4m)
- For an actor subclass named
`Bug`

, write a constructor signature with no parameters. - for an world subclass class named
`WildWorld`

, write a constructor signature with no parameters. - The name of the class that contains this code is _____.
private Dog dog; private Rabbit rabbit; public RabitPatch() {/* statements here */}

- For an actor subclass named
- Review your work with another student in the class and correct any problems.

- Write the heading for this problem on your paper.
- Review lesson 4.4.4: Arithmetic
- On your paper, write the question number and a solution to the following problems:
- First operation performed in
`1 + 2 * 3 / 4 % 5`

is ________. - The value of x after the following code executes is ________.
double x = 9 / 4;

*Hint*: run the code.Why do we get that result?

- The value of x after the following arithmetic expression and assignment is ________.
double x = 1 + 2 * 3 / 4 % 5;

- Write the following math expression as Java code:

- First operation performed in
- Review your work with another student in the class and correct any problems.

- Of the following, the one that is NOT a complete statement for adding 1 to
`numAnts`

is ________.`numAnts + 1;`

`numAnts = numAnts + 1;`

`numAnts = 1 + numAnts;`

`numAnts = numAnts + 1 / 1;`