AP Computer Science Java Review

¡Supera tus tareas y exámenes ahora con Quizwiz!

What does a for loop look like?

(for int i=0< count; i++) { /*code to execute count times */ }

What are pre-conditions in commenting?

What assumptions we make and what must be true before the method is called

What does a single-line comment look like?

// This is a single-line comment

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 2 and Avenue 6

What are rows known as in Karel's world?

Streets

How do you write "turnRight" in a program using a private void?

private void turnRight() { turnLeft(); turnLeft(); turnLeft(); }

What are comments in Java?

A way for you to leave notes about what your code is doing in plain English , so other people can understand it

What do we use control structures for in Java?

A.) Control the flow of the program; how the commands execute

What do we use control structures for in Java? A.) Control the flow of the program; how the commands execute B.) Start our Java program C.) Store information for later D.) Teach Karel new commands

A.) Control the flow of the program; how the commands execute

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

A.) 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 is a valid Java Karel command? A.) move(); B.) move; C.) move() D.) move(5)

A.) move();

What is an if/else statement?

An if/else statement runs some code if a condition is true , and another block of code if that condition is false

What are the columns known as in Karel's world

Avenues

To maintain good style, where should brackets go in Java programming? A.) Before defining the run method B.) Always on their own line C.) Right after defining a method D.) Two brackets per line

B.) Always on their own line

What can be used to teach Karel to turn right? A.) Variables B.) Methods C.) Dog Treats D.) Karel can already turn right

B.) Methods

Why do we use if statements in Java? A.) To break out of some block of code B.) To do something only if a condition is true C.) To do something while a condition is true D.) To repeat something for a fixed number of times

B.) To do something only if a condition is true

Why do we use if/else statements in Java? A.) To repeat something for a fixed number of times B.) To either do something if a condition is true or do something else C.) To break out of some block of code D.) To repeat something while a condition is true

B.) To either do something if a condition is true or do something else

Which is the correct way of naming a method? A.) blahblah() B.) buildTower() C.) 7movesup

B.) buildTower()

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 }

B.) if(condition) { //code }

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(); }

B.) private void spin() { turnLeft(); turnLeft(); turnLeft(); turnLeft(); }

Why do we use while loops in Java? A.) To break out of some block of code B.) To do something if a condition is true C.) To repeat some code while a condition is true D.) To repeat something for a fixed number of times

C.) To repeat some code while a condition is true

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 }

C.) for(int i = 0; i < count; i++) { //code }

Why do we use methods in Java programming? A.) Break down our program into smaller parts B.) Avoid repeating code C.) Make our program more readable D.) All of the above

D.) All of the above

Why should a programmer indent their code? A.) Helps show the structure of the code B.) Easier for other people to understand C.) Indenting is a key part of good programming style D.) All of the above

D.) All of the above

Which of the below are examples of control structures? (I) if (II) if/else (III) while (IV) for A.) I only B.) I and II only C.) III and I only D.) I, II, III, IV

D.) I, II, III, IV

Why do we use for loops in Java? A.) To break out of some block of code B.) To do something if a condition is true C.) To do something while a condition is true D.) To repeat something for a fixed number of times

D.) To repeat something for a fixed number of times

Why do we use methods in a Java program for Karel? A.) To stop the Java program B.) To display the current row that Karel is in C.) We do not use methods in Java D.) To teach Karel new commands

D.) To teach Karel new commands

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 }

D.) if(condition) { //code } else { //code }

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

D.) public class FunProgram extends SuperKarel

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 }

D.) public void run() { //code }

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 }

D.) while(condition) { //code }

How do you write a Java Class with Run Method?

public class SquareKarel extends Karel { public void run () { // our code goes here } }

How do you write a Java Class?

public class SquareKarel extends Karel { }

What is a code comment? A.) A way to teach Karel a new word B.) A way to give notes to the reader to explain what your code is doing C.) A message to your teacher in code D.) A place to write whatever you want in your code

qB.) A way to give notes to the reader to explain what your code is doing

What commands does SuperKarel know that regular Karel does not? A.) turnLeft() and jump() B.) turnRight() and jump() C.) turnLeft() and move() D.) turnAround() and turnRight()

turnAround() and turnRight()

How do you tell Karel to turn right in a program?

turnLeft(); turnLeft(); turnLeft();

What do While Loops code look like?

while (condition) { /* code to repeat */ }

What is an example of a While Loop?

while (frontIsClear) { move(); }

What is SuperKarel?

SuperKarel understands the methods of turnAround() and turnRight()

What is the run method in a Java program with Karel? A.) A method that always makes Karel move in a square. B.) The method that is called just before the program ends. C.) The method that is called to start a Karel program. D.) The method that is called in order to move Karel one space forward.

The method that is called to start a Karel program

What is the Run Method?

The place where our program starts running public void run() { }

What are methods?

The way to teach Karel new words

What are post-conditions in commenting?

What should be true after the method is called

What are While Loops?

While loops allow us to repeat a section of code as long as some condition is true

What is a condition?

A condition is a method that returns a true/false answer

What does the code of an if/else statement look like?

if (condition) { /* code if condition is true*/ } else (condition) { /* code to run otherwise*/ }

What is an if/else statement example?

if (frontIsClear()) { move(); } else { turnLeft(); }

What is an If Statement example?

if (frontIsClear()) { move(); }

What does the code look like of an If Statement?

if(condition) { /*code goes here*/ }

Which control structures repeat code?

-For Loop -While Loop

Why do we indent our code?

-Help show structure of code -Easier for other people to understand -A key part of good programming style

Which control structures ask questions?

-If Statements - If-Else statements

How should you name a method?

-Name should start with a letter, no numbers -Every new word begins with a uppercase letter -The name should describe what the function does -The name should start with an action verb

What are the Karel Conditions?

-frontIsClear() -LeftIsClear() -RightIsClear() -ballsPresent() -facingNorth() -facingEast() -frontIsBlocked() -leftIsBlocked() -rightIsBlocked() -noBallsPresent() -facingSouth() -facingWest()

What are the four valid commands Karel knows?

-move(); -turnLeft(); -putBall(); -takeBall();

What is a multi-line comment look like?

/* Leave a comment so a reader * understands what your * program is doing */

What is the method body?

Everything that is between the brackets

What is The For Loop?

For loop let Karel repeat a section of code a fixed number of times


Conjuntos de estudio relacionados

Corporate Social Responsibility and Business Ethics

View Set

Nissan 2023 Sentra Certification

View Set

GEO 102: CHAPTER 3 PRACTICE QUIZ

View Set

Another word instead of the word "I think".

View Set

Multimedia News Writing Chapter 4

View Set

Chapter 2: Polar Covalent Bonds and Acids/Bases

View Set

Chapter 13: Saving Investment and the Financial System- Macroeconomics

View Set