Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Karel Java Test

Total questions: 28

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is a valid Karel command?

a)

move;

b)

Move();

c)

move();

d)

move()

2.

Which of the following is a valid Karel command?

a)

TurnLeft();

b)

turn left;

c)

turn left();

d)

turnLeft();

3.

What command do you use to add a ball at Karel's current location?

a)

addBall();

b)

putBall();

c)

placeBall();

d)

takeBall();

4.

Which of the following is not true about a Karel command?

a)

Command names can only be made up of one word

b)

Commands do not have any spaces

c)

Capitalization has to match exactly

d)

Every command ends in ();

5.

By default, Karel knows how to turn right.

a)

True

b)

False

6.

If Karel is currently facing South, then after you call turnLeft(); Karel will be facing _.

a)

North

b)

South

c)

East

d)

West

7.

When using CodeHS, the method that contains all the main code that will execute when you click "Run!" is called

a)

start

b)

main

c)

run

d)

begin

8.

All commands must be inside of a method.

a)

True

b)

False

9.

What is the most appropriate method name for the following?


private void _(){

turnLeft();

turnLeft();

turnLeft();

}

(a)  

10.

Once we define a method, we can then call it in other methods to replace the sequence of commands that are in the method we defined.

a)

True

b)

False

11.

Which is the correct class signature for a Karel program named DizzyKarel

a)

public class DizzyKarel extends Karel

b)

public class DizzyKarel < Karel

c)

public DizzyKarel

d)

DizzyKarel extends Karel

12.

What is top down design?

a)

It is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.

b)

It is when you start at the top of the program and work your way down the file to solve the problem.

c)

It is when you write down a list of all the commands that are needed for the program and then start solving it.

d)

It is when you use loops and control structures to break-down a problem.

13.

Which of the following is the valid syntax for a single line comment?

a)

** This is a comment

b)

// This is a comment

c)

This is a comment //

d)

[ This is a comment ]

14.

Which of these is a valid header for a for loop?

a)

for (int i = 0; < 5; i++)

b)

for (i = 0; i < 5; i++)

c)

for (int i = 0; i < 5; i++)

d)

for (int i = 0; I < 5; i++)

15.

How many times will Karel move based on this loop?


for (int i = 0; i < 4; i++)

{

move();

}

(a)  

16.

How many times will this loop repeat?


for (int i = 1; i < 10; i++)

{

move();

}

a)

10

b)

9

c)

11

d)

Repeats forever

17.

Is proper indentation required for a program to run?

a)

Yes

b)

No

18.

Proper indentation makes code easier to read and is good programming style.

a)

True

b)

False

19.

To teach Karel a new command, we need to

a)

use a for loop

b)

use an if statement

c)

send it to training school

d)

define a new method

20.

What is wrong with the following method declaration?


public turnAround()

{

turnLeft();

turnLeft();

}

a)

Not using the correct brackets

b)

Missing void

c)

The method name should start with a capital letter

d)

Missing a semicolon

21.

What is wrong with the following method declaration?


public void turnAndMove()

[

turnLeft();

move();

]

a)

Using the wrong brackets

b)

Missing key term

c)

Missing semicolon

d)

Method name should start with a capital letter

22.

A condition is a method or statement that returns a value of true or false and is generally used within a control structure

a)

True

b)

False

23.

When you see a pair of _, it is good programming style to indent all the lines of code between them

a)

()

b)

""

c)

{}

d)

[]

24.

When you need to repeat an action an unknown number of times, you should use a _

a)

for loop

b)

while loop

c)

if statement

d)

if/else statement

25.

When you need to decide which of two actions you should perform, you should use a _.

a)

for loop

b)

while loop

c)

if statement

d)

if/else statement

26.

Which condition should you use to determine if there is a wall so you can turn Karel?

a)

leftIsClear()

b)

frontIsClear()

c)

rightIsClear()

d)

frontIsBlocked()

27.

Let's say Karel is currently on top of one ball. What will the following code do?


while(ballsPresent())

{

turnLeft();

putBall();

}

a)

It will turn left and then stop

b)

It will turn left, place another ball and then stop.

c)

It will continue to turn left and place another ball in an infinite loop

d)

It will not do anyting

28.

Which of the following is the proper syntax?

a)

if leftIsClear()

{

putBall();

}

b)

if (leftIsClear())

{

putBall();

}

c)

if (leftIsClear())

[

putBall();

]

d)

if (leftIsClear());

{

putBall();

}