NEW
Font size
WorksheetsUnit 1
Total questions: 20
Worksheet time: 2hrs 40mins
What is a condition in Karel programming?
The place in code where the program stops running.
A method that returns a true or false answer. Typically used within a control structure.
The number of times a program loops.
What karel does during the program.
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
I only
I and II
IV only
I onlyI and IIIV onlyI, II, and IV
II and III
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
I only
I and II
I onlyI and III, II, and III
I, II, III, IV
How can we teach Karel new commands?
A for loop
A while loop
Define a new method
The run method
Why does a programmer indent their code?
Helps show the structure of the code.
Easier for other people to understand.
A key part of good programming style!
All of the above
Which of these is a valid Karel command in Java?
move();
MOVE
move;
move()
Which of these is a valid Karel command in Java?
turnLeft();
turnleft();
turnLeft()
TurnLeft
public class FunKarel extends Karel
{
public void run()
{
move();
putBall();
move();
}
}
What is the name of this class?
Karel
FunKarel
Run
SuperKarel
What is the name of the method that gets called to start a Java Karel program?
go()
start()
run()
move()
Which is the correct class signature for a Karel program named CleanupKarel?
public class CleanupKarel extends Karel
public class CleanupKarel < Karel
public CleanupKarel
CleanupKarel extends Karel
Which of these methods will create a method called turnRight that will have Karel turn left three times?
private void turnRight
{
turnLeft();
turnLeft();
turnLeft();
}
private void turnRight()
{
turnLeft
turnLeft
turnLeft
}
private void turnRight()
{
turnLeft();
turnLeft();
turnLeft();
}
private turnRight()
{
turnLeft();
turnLeft();
turnLeft();
}
What is a method in Karel?
A method is the name for an entire Java programA method is something that lets you repeat a command a fixed number of times
A method is a command that Karel can do. It has a name and a set of instructions.
A method is the way that you leave a note for someone else who reads the code.
What is top down design?
Top down design is a way to use loops and classes to decompose the problem
Top down design is a way that you can create designs on a computer to put on a web page
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.
Which of these show the proper format for a Java comment?
/*
*
* My java comment
*/
// My java comment
All of the above
What is the correct class signature in Java for a SuperKarel program?
public class FunKarel << SuperKarel
public class FunKarel extends Karel
public class FunKarel extends SuperKarel
public FunKarel extends SuperKarel
Which of these loops has Karel move 5 times?
for(int i = 0; i <= 5; i++)
{
move();
}
for(int i = 1; i < 5; i++)
{
move();
}
for(int i = 0; i < 5; i++)
{
move();
}
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();
}
88
45
108
107
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?
while(frontIsClear())
{
move();
}
while(frontIsBlocked())
{
move();
}
for(int i = 0; i < 10; i++)
{
move();
}
If Karel is not on a tennis ball, and all directions around are clear:
What will happen when running this code?
while(noBallsPresent())
{
turnLeft();
}
Karel will stay where he is and not move
Karel will go into an infinite loop
Karel will put down a tennis ball
What is the correct syntax for an if statement?
if frontIsClear()
{
move();
}
if(frontIsClear())
{
move();
}
if(frontIsClear())
[
move();
]
