WorksheetsKarel Java Test
Total questions: 28
Worksheet time: 15mins
Which of the following is a valid Karel command?
move;
Move();
move();
move()
Which of the following is a valid Karel command?
TurnLeft();
turn left;
turn left();
turnLeft();
What command do you use to add a ball at Karel's current location?
addBall();
putBall();
placeBall();
takeBall();
Which of the following is not true about a Karel command?
Command names can only be made up of one word
Commands do not have any spaces
Capitalization has to match exactly
Every command ends in ();
By default, Karel knows how to turn right.
True
False
If Karel is currently facing South, then after you call turnLeft(); Karel will be facing _.
North
South
East
West
When using CodeHS, the method that contains all the main code that will execute when you click "Run!" is called
start
main
run
begin
All commands must be inside of a method.
True
False
What is the most appropriate method name for the following?
private void _(){
turnLeft();
turnLeft();
turnLeft();
}
(a)
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.
True
False
Which is the correct class signature for a Karel program named DizzyKarel
public class DizzyKarel extends Karel
public class DizzyKarel < Karel
public DizzyKarel
DizzyKarel extends Karel
What is top down design?
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.
It is when you start at the top of the program and work your way down the file to solve the problem.
It is when you write down a list of all the commands that are needed for the program and then start solving it.
It is when you use loops and control structures to break-down a problem.
Which of the following is the valid syntax for a single line comment?
** This is a comment
// This is a comment
This is a comment //
[ This is a comment ]
Which of these is a valid header for a for loop?
for (int i = 0; < 5; i++)
for (i = 0; i < 5; i++)
for (int i = 0; i < 5; i++)
for (int i = 0; I < 5; i++)
How many times will Karel move based on this loop?
for (int i = 0; i < 4; i++)
{
move();
}
(a)
How many times will this loop repeat?
for (int i = 1; i < 10; i++)
{
move();
}
10
9
11
Repeats forever
Is proper indentation required for a program to run?
Yes
No
Proper indentation makes code easier to read and is good programming style.
True
False
To teach Karel a new command, we need to
use a for loop
use an if statement
send it to training school
define a new method
What is wrong with the following method declaration?
public turnAround()
{
turnLeft();
turnLeft();
}
Not using the correct brackets
Missing void
The method name should start with a capital letter
Missing a semicolon
What is wrong with the following method declaration?
public void turnAndMove()
[
turnLeft();
move();
]
Using the wrong brackets
Missing key term
Missing semicolon
Method name should start with a capital letter
A condition is a method or statement that returns a value of true or false and is generally used within a control structure
True
False
When you see a pair of _, it is good programming style to indent all the lines of code between them
()
""
{}
[]
When you need to repeat an action an unknown number of times, you should use a _
for loop
while loop
if statement
if/else statement
When you need to decide which of two actions you should perform, you should use a _.
for loop
while loop
if statement
if/else statement
Which condition should you use to determine if there is a wall so you can turn Karel?
leftIsClear()
frontIsClear()
rightIsClear()
frontIsBlocked()
Let's say Karel is currently on top of one ball. What will the following code do?
while(ballsPresent())
{
turnLeft();
putBall();
}
It will turn left and then stop
It will turn left, place another ball and then stop.
It will continue to turn left and place another ball in an infinite loop
It will not do anyting
Which of the following is the proper syntax?
if leftIsClear()
{
putBall();
}
if (leftIsClear())
{
putBall();
}
if (leftIsClear())
[
putBall();
]
if (leftIsClear());
{
putBall();
}
