Posts

Computer Science: Application Multiple Choice

Computer Science: Application Multiple Choice

1. Which of these is a valid Java Karel command?

move;
move();
move()
move(5);

 

2. If Karel starts at Street 1 and Avenue 3 facing East, what row and column will Karel be on after this code runs?

move();

move();

move();

turnLeft();

move();

Street 1 and Avenue 3
Street 4 and Avenue 4
Street 2 and Avenue 6
Street 6 and Avenue 2

 

3. If Karel is facing North and the code

turnLeft();

turnLeft();

runs; which direction is Karel facing now?

North
South
East
West

 

4. What is the run method in a Java program with Karel?

A method that always makes Karel move in a square.
The method that is called just before the program ends.
The method that is called to start a Karel program.
The method that is called in order to move Karel one space forward.

 

5. What does a Karel run method look like?

A

public run()

{

//code

}

 

B

public run(){

//code

}

 

C

public void run

{

//code

}

 

D

public void run()

{

//code

}

A
B
C
D

 

6. What can be used to teach Karel to turn right?

Variables
Methods
Dog treats
Karel can already turn right

 

7. Why do we use methods in a Java program for Karel?

To stop the Java program
To display the current row that Karel is in
We do not use methods in Java
To teach Karel new commands

 

8. Which method will teach Karel how to spin in a circle one time?

A

private void spin()

{

turnRight();

}

 

B

private void spin()

{

turnLeft();

turnLeft();

turnLeft();

turnLeft();

}

 

C

private void spin()

{

turnLeft();

turnLeft();

}

 

D

private void spin()

{

move();

move();

move();

move();

}

A
B
C
D

 

9. Why do we use methods in Java programming?

Break down our program into smaller parts
Avoid repeating code
Make our program more readable
All of the above

 

10. What is top down design?

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.
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 programs starting with the individual commands first
Top down design is a way to use loops and classes to decompose the problem

 

11. What is a code comment?

A way to teach Karel a new word
A way to give notes to the reader to explain what your code is doing
A message to your teacher in code
A place to write whatever you want in your code

 

12. How do you write a SuperKarel class?

A

public class FunProgram extends Karel

 

B

private class FunProgram extends Karel

 

C

class FunProgram extends SuperKarel

 

D

public class FunProgram extends SuperKarel

A
B
C
D

 

13. What commands does SuperKarel know that regular Karel does not?

turnLeft() and jump()
turnRight() and jump()
turnLeft() and move()
turnAround() and turnRight()

 

14. Why do we use for loops in Java?

To break out of some block of code
To do something if a condition is true
To do something while a condition is true
To repeat something for a fixed number of times

 

15. Which general for loop definition is written correctly?

A

for(true)

{

// code

}

 

B

if(i<5)

{

//code

}

 

C

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

{

//code

}

 

D

while(condition)

{

//code

}

A
B
C
D

 

16. Why do we use while loops in Java?

To break out of some block of code
To do something if a condition is true
To repeat some code while a condition is true
To repeat something for a fixed number of times

 

17. Which general while loop definition is written correctly?

A

while(x is true)

{

// code

}

 

B

if(i<5)

{

//code

}

 

C

while(int i = 0; i < count; i++)

{

//code

}

 

D

while(condition)

{

//code

}

A
B
C
D

 

18. Why do we use if statements in Java?

To break out of some block of code
To do something only if a condition is true
To do something while a condition is true
To repeat something for a fixed number of times

 

19. Which general if statement definition is written correctly?

A

for(condition)

{

// code

}

 

B

if(condition)

{

//code

}

 

C

if(int i = 0; i < count; i++)

{

//code

}

 

D

if(false)

{

//code

}

A
B
C
D

 

20. Why do we use if/else statements in Java?

To repeat something for a fixed number of times
To either do something if a condition is true or do something else
To break out of some block of code
To repeat something while a condition is true

 

21. What does an if/else statement look like in Java?

A

if(condition)

{

//code

}

 

B

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

{

//code

}

 

C

if(condition)

{

//code

}

if(condition)

{

//code

}

 

D

if(condition)

{

//code

}

else

{

//code

}

A
B
C
D

 

22. What do we use control structures for in Java?

Control the flow of the program; how the commands execute.
Start our Java program
Store information for later
Teach Karel new commands

 

23. Which of the below are examples of control structures?

(I) if

(II) if/else

(III) while

(IV) for

I only
I and II only
III and I only
I, II, III, and IV

 

24. Why should a programmer indent their code?

Helps show the structure of the code
Easier for other people to understand
Indenting is a key part of good programming style
All of the above

 

25. To maintain good style, where should brackets go in Java programming?

Before defining the run method
Always on their own line
Right after defining a method
Two brackets per line

 

26. Which of these is a valid Karel command in Java?

move();
MOVE
move;
move()

 

27. Which of these is a valid Karel command in Java?

turnLeft();
turnleft();
turnLeft()
TurnLeft

28.

public class FunKarel extends Karel

{

public void run()

{

move();

putBall();

move();

}

}

What is the name of this class?

Karel
FunKarel
Run
SuperKarel

 

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

go()
start()
run()
move()

 

30. 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

 

31. 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();

}

A
B
C
D

 

32. What is a method in Karel?

A method is the name for an entire Java program
A 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.

 

33. What is top down design?

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.
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 programs starting with the individual commands first
Top down design is a way to use loops and classes to decompose the problem

 

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

 

A

/*

*

* My java comment

*/

 

B

/**

*

* My java comment

*/

 

C

// My java comment

 

D

All of the above

A
B
C
D

 

35. Which of these is a valid way to write a single line comment in Java?

 

A

// This is a comment

 

B

++ This is a comment

 

C

This is a comment //

 

D

/* This is a comment

A
B
C
D

 

36. 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

A
B
C
D

 

37. Which of these loops has Karel move 7 times?

 

A

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

{

move();

}

 

B

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

{

move();

}

 

C

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

{

move();

}

 

D

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

{

move();

}

A
B
C
D

 

38. Which of these loops will run correctly 10 times?

 

A

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

{

turnLeft();

}

 

B

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

{

turnLeft();

}

 

C

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

{

turnLeft();

}

 

D

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

{

turnLeft();

}

A
B
C
D

 

39. 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();

}

100
1
3
106
107

 

40. Which of these code snippets 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

while(frontIsClear())

{

turnLeft();

move();

}

 

D

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

{

move();

}

A
B
C
D

 

41. If Karel is not on a tennis ball, and all directions around are clear:  https://s3.amazonaws.com/f.cl.ly/items/41372Z3y2b1j2N0U1m3e/Screen%20Shot%202015-11-11%20at%209.55.24%20PM.png

What will happen when running this code?

while(noBallsPresent())

{

turnLeft();

}

Karel will not do anything
Karel will go into an infinite loop
Karel will put down a tennis ball
Karel will turn left once

 

42. What is the correct syntax for an if statement?

 

A

if frontIsClear()

{

move();

}

 

B

if(frontIsClear())

{

move();

}

 

C

if(frontIsClear())

[

move();

]

 

D

if(frontIsClear())

(

move();

)

A
B
C
D

 

43. If Karel is directly in front of a wall, which condition would properly check if a wall is in front and turn left, and otherwise would move?

if(<CONDITION>)

{

turnLeft();

}

else

{

move();

}

leftIsClear()
frontIsClear()
facingNorth()
frontIsBlocked()

 

44. Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

An if statement
A for loop
A while loop
A nested while loop

 

45. Say you want to write a program to have Karel to pick up all of the tennis balls in a location, but you don’t know how many tennis balls there are. Which control structure would you use?

An if statement
A for loop
A while loop
An if/else statement

 

46. 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.

 

47. 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, II, and IV
II and III

 

48. 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, II, and III
I, II, III, IV

 

49. How can we teach Karel new commands?

A for loop
A while loop
Define a new method
The run method

 

50. 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
 
Do you need a similar assignment done for you from scratch? Order now!
Use Discount Code "Newclient" for a 15% Discount!