wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Unit 1

Total questions: 20

Worksheet time: 2hrs 40mins

Name
Class
Date
1.

What is a condition in Karel programming?

a)

The place in code where the program stops running.

b)

A method that returns a true or false answer. Typically used within a control structure.

c)

The number of times a program loops.

d)

What karel does during the program.

2.

What is wrong with the style of this method declaration?

private void spinKarel() {

turnLeft();

turnLeft();

turnLeft();

turnLeft();

}


(I) Indenting is wrong

(II) No comment

(III) Not using camelCasing for name

(IV) Brackets are not on their own line

a)

I only

b)

I and II

c)

IV only

d)

I onlyI and IIIV onlyI, II, and IV

e)

II and III

3.

What is wrong with this method declaration?

public karelDance()

[

move();

turnLeft();

move();

turnLeft();

move();

]

(I) Not using curly brackets

(II) Missing void

(III) Using public instead of private

(IV) Illegal characters in the method name

a)

I only

b)

I and II

c)

I onlyI and III, II, and III

d)

I, II, III, IV

4.

How can we teach Karel new commands?

a)

A for loop

b)

A while loop

c)

Define a new method

d)

The run method

5.

Why does a programmer indent their code?

a)

Helps show the structure of the code.

b)

Easier for other people to understand.

c)

A key part of good programming style!

d)

All of the above

6.

Which of these is a valid Karel command in Java?

a)

move();

b)

MOVE

c)

move;

d)

move()

7.

Which of these is a valid Karel command in Java?

a)

turnLeft();

b)

turnleft();

c)

turnLeft()

d)

TurnLeft

8.

public class FunKarel extends Karel

{

public void run()

{

move();

putBall();

move();

}

}

What is the name of this class?

a)

Karel

b)

FunKarel

c)

Run

d)

SuperKarel

9.

What is the name of the method that gets called to start a Java Karel program?

a)

go()

b)

start()

c)

run()

d)

move()

10.

Which is the correct class signature for a Karel program named CleanupKarel?

a)

public class CleanupKarel extends Karel

b)

public class CleanupKarel < Karel

c)

public CleanupKarel

d)

CleanupKarel extends Karel

11.

Which of these methods will create a method called turnRight that will have Karel turn left three times?

a)

private void turnRight

{

turnLeft();

turnLeft();

turnLeft();

}

b)

private void turnRight()

{

turnLeft

turnLeft

turnLeft

}

c)

private void turnRight()

{

turnLeft();

turnLeft();

turnLeft();

}

d)

private turnRight()

{

turnLeft();

turnLeft();

turnLeft();

}

12.

What is a method in Karel?

a)

A method is the name for an entire Java programA method is something that lets you repeat a command a fixed number of times

b)

A method is a command that Karel can do. It has a name and a set of instructions.

c)

A method is the way that you leave a note for someone else who reads the code.

13.

What is top down design?

a)

Top down design is a way to use loops and classes to decompose the problem

b)

Top down design is a way that you can create designs on a computer to put on a web page

c)

Top down design 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.

14.

Which of these show the proper format for a Java comment?

a)

/*

*

* My java comment

*/

b)

// My java comment

c)

All of the above

15.

What is the correct class signature in Java for a SuperKarel program?

a)

public class FunKarel << SuperKarel

b)

public class FunKarel extends Karel

c)

public class FunKarel extends SuperKarel

d)

public FunKarel extends SuperKarel

16.

Which of these loops has Karel move 5 times?

a)

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

{

move();

}

b)

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

{

move();

}

c)

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

{

move();

}

17.

In the code snippet below, how many times will the putBall command run?

putBall();


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

{

putBall();

}


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

{

putBall();

}

a)

88

b)

45

c)

108

d)

107

18.

Which of these would be the best implementation of a method called moveToWall() which moves Karel to the end of a row in the current direction?

a)

while(frontIsClear())

{

move();

}

b)

while(frontIsBlocked())

{

move();

}

c)

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

{

move();

}

19.

If Karel is not on a tennis ball, and all directions around are clear:

What will happen when running this code?

while(noBallsPresent())

{

turnLeft();

}

a)

Karel will stay where he is and not move

b)

Karel will go into an infinite loop

c)

Karel will put down a tennis ball

20.

What is the correct syntax for an if statement?

a)

if frontIsClear()

{

move();

}

b)

if(frontIsClear())

{

move();

}

c)

if(frontIsClear())

[

move();

]