Ap Computers

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the proper format for a single line comment in Karel? This is a comment (big) // This is a comment /* This is a comment This is a comment

// This is a comment

What will the value of yourBankAccount be after the method call? int yourBankAccount = 0; public void depositMoney(int bankAccount, int deposit) { bankAccount += deposit; } depositMoney(yourBankAccount, 1000000); 1000000 0 100000 The code will error.

0

What will this method call output? public int myMethod(boolean x, boolean y) { if(!x) { if(y) { return 1; } else { return 0; } } else { return -1; } } myMethod(false,false) 1 0 -1 This method call will error.

0

Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location? for (var i = 0; i < 3; i++) { if (ballsPresent()) { takeBall(); } else { putBall(); putBall(); } } 0 1 2 6

1

What does this method call output? public int trickyMethod(int x, int y) { int sum = 0; while (x <= 10) { sum += x % y; x++; y++; } return sum; } trickyMethod(3,1) 9 10 11 12

12

What will this method call print to the screen? public void numberMadness(double myDouble) { int myInt = (int) myDouble; String myString = ""; while(myInt != 0) { myString = myInt % 10 + myString; myInt /= 10; } System.out.println(myString); } numberMadness(12345) 12345 54321 123 543

12345

In the following code, what will be the last number to print to the screen before the program finishes? for (var i = 0; i < 10; i++) { if (i % 2 == 0) { println(i); } else { println(2 * i); } } 10 20 9 18

18

What does this method call output? public double doubleOrNothing(double myDouble) { return (double) (int) myDouble * 2; } doubleOrNothing(9.9); 20 18.8 18.0 This method is improperly written.

18.0

How many possible values can Randomizer.nextBoolean() return? 0 1 2 3

2

What is the proper operator for "not equals" in JavaScript? =! != ~= NOT EQUALS

!=

What will this method call output? public String yesOrNo(boolean myBoolean) { if(myBoolean == true) { return "Yes"; } else { return "No"; } } yesOrNo(true) "No" "Yes" 0 This program will error

"Yes"

What is returned by this method call: translator("pokemon")? public String translator(String word) { return word.substring(1) + word.charAt(0) + "ay"; } "pokemonpay" "okemonpay" "okemonay" This method call will error.

"okemonpay"

What will this method call print? public void patternGrid(int rows, int columns, char symbol) { for(int m = 0; m < rows; m++) { for(int n = 0; n < columns; n++) { System.out.print(symbol); } System.out.println(); } } patternGrid(3,4,'#'); #### #### #### ### ### ### #### #### #### #### This code will error.

#### #### ####

What symbol do you use to do division in JavaScript? % / // *

/

What will this method call output? public int mysteryMethod(String x, char y) { int z = 1; for(int i = 0; i < x.length(); i++) { if(x.charAt(i) == y) { z++; } } return z; } mysteryMethod("Karel The Dog", 'e'); 1 2 3 4

3

How many total times will Karel move in this program? function start() { move(); for (var i = 0; i < 5; i++) { move(); putBall(); } } 1 5 6 7

6

What would this method call output? public int myMethod(int num) { while(num / 10 >= 10) { num /= 10; } return num; } myMethod(830) 830 30 0 8 83

83

What is the return value of this method call? public static String someWhereInTheMiddle(int number) { String stringNum = "" + number; int middle = stringNum.length()/2; if(stringNum.length() % 2 == 1) { return stringNum.substring(middle,middle+1); } else { return stringNum.substring(middle-1,middle+1); } } someWhereInTheMiddle(188603) 8 6 7 86

86

Which of the following is the proper format for an HTML tag? >h1<Content Affected by Tag >/h1< <h1>Content Affected by Tag<h1> <h1 Content Affected by Tag /> <h1>Content Affected by Tag</h1>

<h1>Content Affected by Tag</h1>

An image is hosted at https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg Which of the following is the proper HTML code to display this image on your webpage? <a href="https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg">Image</a> <img>https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg</img> <img src="https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg"> <img src="https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg"></img>

<img src="https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg">

What is a return value? The value that a method prints to the screen. The value that is inputted to a method. The value that a user inputs to a program. The value that a method outputs.

A value that a method outputs

In this code, how many times is the dance function called and how many times is it defined? function start() { move(); dance(); move(); move(); turnLeft(); dance(); dance(); } function dance() { turnLeft(); move(); turnLeft(); turnLeft(); move(); turnLeft(); } Called 1 time, defined 1 time Called 1 time, defined 3 times Called 3 times, defined 1 time Called 3 times, defined 3 times

Called 3 times, defined 1 time

How can we teach Karel new commands? For loop While loop Define a new function The start function

For loop

What is generated from the following HTML code: <h1>Hello</h1> <h3>Hello</h3> <h6>Hello</h6>

Hello (big) Hello (medium) Hello (small)

Which of the following statements are true about styling your web pages with CSS: I. Styling with CSS is more scalable than using style= on each HTML tag that you want to style II. You can create styles with CSS that are not possible using style= on an HTML tag I only II only I and II Neither I nor II

I only

What is wrong with this method definition? public String outputString(String input) { System.out.println(input); } The method should not be public Improper return value Improper variable names All of the above

Improper return value

In the following code, what would be a good Postcondition to write? /* Precondition: Karel is on a spot with a tennis ball facing East * Postcondition: ... */ function getOnTop() { turnLeft(); move(); turnRight(); }

Karel ends one spot above a tennis ball facing East.

What does the mystery function do? function mystery() { while (noBallsPresent()) { move(); } } Karel moves until it is on a ball Karel moves once if there is no ball present Karel moves until it puts down a ball Karel checks if there is no ball on the current spot and then moves once

Karel moves until it is on a ball

Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); move(); turnRight(); move(); Karel ends on street 1, avenue 3 Karel ends on street 2, avenue 3 This code won't run because of a syntax error Karel will crash into a wall

Karel will crash into a wall

What will this method call print to the screen? public static void someMethod(int a, String b, int c) { System.out.println(b + " " + a + ", " + c); } someMethod(9,"Mar", 1250) 9 Mar 1250 Mar 9 1250 9, Mar 1250 Mar 9, 1250

Mar 9, 1250

CSS rules have a selector that defines which HTML elements the rule applies to. We've learned about the following CSS Selectors: Select by tag name Select by class name Select by id name Which of the following ranks the selectors from highest precedence to lowest precedence? Select by tag name, select by class name, select by id name Select by id name, select by tag name, select by class name Select by id name, select by class name, select by tag name Select by class name, select by id name, select by tag name

Select by id name, select by class name, select by tag name

If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size) move(); turnLeft(); putBall(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft(); Street 3, Avenue 1, Facing North Street 1, Avenue 4, Facing North Street 1, Avenue 3, Facing South Street 1, Avenue 3, Facing North

Street 1, Avenue 3, Facing North

Which of the following returns a random number between 1 and 10? randomInt(1, 10) randInt(1, 10) Randomizer.int(1, 10) Randomizer.nextInt(1, 10)

Randomizer.nextInt(1, 10)

What kind of error does this method cause? public void buggyMethod(String x) { for(int i = 0; i <= x.length(); i++) { System.out.println(x.substring(i, i+1)); } } buggyMethod("BUG"); Compile Time Error: Unexpected return value Runtime Error: String index out of range Compile Time Error: Missing return value Compile Time Error: Syntax Error in method definition

Runtime Error: String index out of range

What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location? while (________) { takeBall(); } noBallsPresent() ballsPresent() frontIsClear() takeBall()

ballsPresent()

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <p class="fire" id="title">Hello World!</p> red blue green black

blue

What statement can we use inside of a loop to end it? println break for else

break

Which of the following is the correct way to define a turnRight function in Karel? function turnRight() { turnLeft(); turnLeft(); * turnLeft(); } function turnRight() { turnRight(); turnRight(); turnRight(); } function turnRight { turnLeft(); turnLeft(); turnLeft(); } turnRight function() { turnLeft(); turnLeft(); turnLeft(); }

function turnRight() { turnLeft(); turnLeft(); turnLeft(); }

What function do you need to call to get the width of the screen? width() getWidth() screenWidth() getScreenWidth()

getWidth()

What are the coordinates of the top right corner of the screen? 0, 0 0, getWidth() getWidth(), 0 getWidth(), getHeight()

getWidth(), 0

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <p class="title">My First Paragraph</p> red blue green black

green

How can we improve the following program? function start() { move(); move(); move(); move(); move(); move(); move(); move(); move(); } Break down this program into more functions Use a for loop to repeat the move command Use a while loop to repeat the move command Fix the indentation of this program

Use a for loop to repeat the move command

What does void mean? Void means that a method returns any value. Void means that a method takes no parameters. Void means that a method returns no value. Void means that a method can take any parameter. ANSWERED

Void means that a method returns no value.

What symbol represents the and operator in JavaScript? AND and & &&

&&

How can we check if a variable num is even? num.isEven() will be true (num % 2 == 0) will be true (num % 2 == 0) will be false (num / 2 == 0) will be true

(num % 2 == 0) will be true

What symbol do you use to do multiplication in JavaScript? x X * #

*

What is the result of the following HTML code:<ol> <li>Bread</li> <li>Milk</li> <li>Eggs</li> </ol>

1. Bread 2. Milk 3. Eggs

How many times will this program print "hello"? var i = 10; while (i > 0) { println("hello"); i--; } 0 10 i This code will loop infinitely

10

What will be the value of sum after this code runs? var START = 1; var END = 4; function start(){ var sum = 0; for(var i = START; i <= END; i++){ sum += i; } } 10 4 1 40

10

How many times will the following program print "hello"? for (var i = 0; i < 5; i++) { println("hello"); } 4 5 6 i

5

How many times will the following code print "hello"? for (var i = 0; i < 8; i += 2) { println("hello"); } 0 2 4 8

4

What will the following code print to the screen? println(2 + 2); 2 + 2 4 22 Nothing

4

How many times will the following code print "hello"? for (var i = 3; i < 8; i++) { println("hello"); } 3 5 6 8

5

Suppose you are making a music streaming website and you want to make a page that displays a user's music library. Which of the following is the proper HTML code to create the following table: <table border="1"> <tr> <td>Title</td> <td>Artist</td> <td>Length</td> </tr> <tr> <td>CD Jam</td> <td>Rooney Pitchford</td> <td>3:55</td> </tr> <tr> <td>Memory</td> <td>Tom Misch</td> <td>5:41</td> </tr> </table> <table border="1"> <tr> <th>Title</th> <th>Artist</th> <th>Length</th> </tr> <tr> <td>CD Jam</td> <td>Rooney Pitchford</td> <td>3:55</td> </tr> <tr> <td>Memory</td> <td>Tom Misch</td> <td>5:41</td> </tr> </table> <table border="1"> <tr> <th>Title</th> <th>CD Jam</th> <th>Memory</th> </tr> <tr> <td>Artist</td> <td>Rooney Pitchford</td> <td>Tom Misch</td> </tr> <tr> <td>Length</td> <td>3:55</td> <td>5:41</td> </tr> </table> <table border="1"> <tr> <th>Title</th> <td>CD Jam</td> <td>Memory</td> </tr> <tr> <th>Artist</th> <td>Rooney Pitchford</td> <td>Tom Misch</td> </tr> <tr> <th>Length</th> <td>3:55</td> <td>5:41</td> </tr> </table>

<table border="1"> <tr> <th>Title</th> <th>Artist</th> <th>Length</th> </tr> <tr> <td>CD Jam</td> <td>Rooney Pitchford</td> <td>3:55</td> </tr> <tr> <td>Memory</td> <td>Tom Misch</td> <td>5:41</td> </tr> </table>

What is the proper way to compare if two values are equal in a boolean expression in JavaScript? = == EQUALS is

==

What is wrong with this for loop? for (var i = 0, i < 10, i + 1) { move(); } A. The for loop uses commas instead of semicolons B. It should say i++ instead of i + 1 A B A and B The for loop is correct

A and B

What is a Javadoc? The reference guide to Java that is in the back of a textbook. A program that cures the bugs in your Java program. Data that gets passed into a method A comment that clearly states the functionality and usage of a class or method.

A comment that clearly states the functionality and usage of a class or method.

What is a method? A procedure that is defined by the user. A keyword used to loop for a fixed amount of time. A place where we can store data. The type that is given to a variable.

A procedure that is defined by the user.

Why do we use constant variables? To avoid having "magic numbers" in our code To give values a readable name, so that their purpose is clear To let us easily change the behavior of our program by only having to change a value in one place All of the above

All of above

Why do we use functions in Karel programs? Break down our program into smaller parts Avoid repeating code Make our program more readable All of the above

All of the above

Why do we use methods in Java? To make code easier to understand To avoid repeated code To simplify code All of the above

All of the above

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

All of the above

Suppose you have written a web page using HTML and CSS and it is hosted at the URL yourdomain.com/home.html Which of the following statements is true about which devices can view your website? Only browsers on desktop computers can view your website because only desktop browsers can render HTML based web pages. Only browsers on mobile phones can view your website because only mobile browsers can render HTML based web pages. Only computers made after the day you publish your website can view your website. Older computers can't understand HTML and CSS. Any browser on any device will be able to view your webpage, because all browsers and devices on the Internet agree to use the same protocols for sending, receiving, and viewing webpages.

Any browser on any device will be able to view your webpage, because all browsers and devices on the Internet agree to use the same protocols for sending, receiving, and viewing webpages.

To ask the user of the program for a number, which function should you use? readLine readInt readFloat Both readInt and readFloat are for numbers.

Both readInt and readFloat are for numbers.

Which of the following best describes the difference between the domain and path of a URL? *The domain specifies where the browser's request should be sent. The path specifies exactly what file is being requested. *The domain specifies what kind of file is being requested. The path specifies the name of the file being requested. *The domain specifies the name of the file being requested. The path specifies what kind of file is being requested. *The domain specifies exactly what file is being requested. The path specifies where the browser's request should be sent

The domain specifies where the browser's request should be sent. The path specifies exactly what file is being requested.

What are parameters? The value that a method returns. The values that a method prints to the screen. The formal names given to the data that gets passed into a method. The type that is given to a variable. ANSWERED

The formal names given to the data that gets passed into a method.

What's wrong with this code? function start() { move(); go(); go(); } function go() { move(); move(); } function go() { move(); move(); } The go function is called twice The go function has a syntax error The go function has been defined twice go is not a command that Karel understands

The go function has been defined twice

What makes the following command an invalid Karel command? turnleft(); It should end in a colon rather than a semicolon The l should be a capital L It should start with a capital T This command is correct

The l should be a capital L

In the following code, we create a circle and add it to the screen. What is the meaning of the x variable? var x = 20; var circle = new Circle(x); add(circle); The color of the circle The diameter of the circle The radius of the circle The position of the circle

The radius of the circle

Which of the following classifies as metadata about a webpage? The tags that make up the body of the webpage A table on a webpage A list on a webpage The title of the webpage

The title of the webpage

How many times will this program print "hello"? var i = 50; while (i < 100) { println("hello"); } 0 50 100 This code will loop infinitely

This code will loop infinitely

Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); putball(); move(); move(); move(); move(); move(); Karel will end on Street 1, Avenue 2 Karel will end on Street 1, Avenue 7 This code won't run because of a syntax error Karel will crash into a wall

This code won't run because of a syntax error

What does this method call return? public int doubleInt(int x) { x * 2; } doubleInt(5); 10 5 This method returns nothing. This method is improperly written.

This method is improperly written

In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2? // This program has Karel walk down the // row and clean up all of the tennis balls // on the way. function start() { while (frontIsClear()) { // If statement #1 if (ballsPresent()) { takeBall(); } move(); } // If statement #2 if (ballsPresent()) { takeBall(); } } To move the last time To pick up the ball that is in the last spot To pick up the ball that is in the last spot, if there is one To take the ball from all of the positions that have a ball on them

To pick up the ball that is in the last spot, if there is one

What is the purpose of using a for loop in code? To do something if a condition is true To do something while a condition is true To repeat something a fixed number of times To make programs run faster

To repeat something a fixed number of times

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 if statements to decompose the problem

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 the following is a valid CSS rule? h1 { color: blue; } <h1> { color: blue; } h1 { color="blue"; } h1 { color=blue; }

h1 { color: blue; }

What kind of statement allows us to run a block code only if a certain condition is true? if statement break statement else statement for loop

if statement

What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise? if statement break statement if/else statement for loop

if/else statement

What will this method call output? public boolean someMethod(int number) { if(number % 2 == 0) { return true; } else { return false; } } someMethod(9990) false 0 "true" true

true

Which of the following commands is a valid Karel command? move move; move(); move()

move();

What is the proper function to call to print to the screen? write println PRINT post

println

Which of the following is not a valid condition to go in an if statement for Karel? ballsPresent() frontIsClear() leftIsBlocked() turnLeft()

turnLeft()

Write a method that will ask for user input until user inputs the String "no". Allow the user to input any capitalization of the String "no" ("no", "No", "NO", "nO") Also, have the method return the number of loops. Use readLine to get the user input. public int loopTillNo() { int count = 0; while(!readLine("Again?").equals("no")) { count++; } return count; } public int loopTillNo() { int count = 0; while(readLine("Again?").toLowerCase().equals("no")) { count++; } return count; } public int loopTillNo() { int count = 0; while(readLine("Again?").equals("no")) { count++; } return count; } public int loopTillNo() { int count = 0; while(!readLine("Again?").toLowerCase().equals("no")) { count++; } return count; }

public int loopTillNo() { int count = 0; while(!readLine("Again?").toLowerCase().equals("no")) { count++; } return count; }

What could the method signature for a Karel command look like? public void move() { //some code } public String move() { //some code } public int move() { //some code } public boolean move() { //some code }

public void move() { //some code }

Write a method that loops forever until the user inputs the correct secret password or until the user fails to enter the correct password 10 times. The secret password the program should look for is the String "secret" Use readLine(String prompt) for user input public void secretPassword() { int count = 1; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } } public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); } count++; } } public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } } public void secretPassword() { int count = 0; while(true) { if(count != 10) { System.out.println("You are locked out!"); return; } if(!readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } }

public void secretPassword() { int count = 0; while(true) { if(count == 10) { System.out.println("You are locked out!"); return; } if(readLine("Password?").equals("secret")) { System.out.println("Welcome!"); return; } count++; } }

What function do you need to call to ask the user of the program to enter text? readLine readln text println

readLine

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <h1 class="fire">Welcome!</h1> red green blue black

red

What is the term for the value that signals the end of user input? sentinel break -1 done

sentinel

After the following code runs, what is the value of isWeekend? var isSaturday = true; var isSunday = false; var isWeekend = isSaturday || isSunday; true false "isWeekend" "isSaturday || isSunday"

true

What keyword do you need to use to define a variable in JavaScript? variable var int x

var

Which of the following is a good example of a proper constant variable name? var max_value = 100; var MAX_VALUE = 100; var Max_Value = 100; var maxValue = 100;

var MAX_VALUE = 100;

Which of the following is correct loop and a half structure? while(condition){ //code } for(var i = 0; i <= 1.5; i++){ //code } while(true){ //code if(condition){ break; } //code } for(var i = 0; i < 2; i++){ //code break; //code }

while(true){ //code if(condition){ break; } //code }

What is the domain of this URL: www.example.com/home.html www home.html www.example.com HTML

www.example.com

Which of the following is not a valid value for a boolean? true false yes The above are all valid

yes

What symbol represents the or operator in JavaScript? OR or | ||

||


संबंधित स्टडी सेट्स

Chapter 13: The Federal Reserve System

View Set

Chapter 16: Managing Organization Culture

View Set

Chapter 5 Practice Questions APES

View Set

Chapter 12: Schizophrenia and Schizophrenia Spectrum Disorders

View Set

AP Art History Paleolithic and Neolithic Period definitions.

View Set

All 44 Presidents with name, party, and years in office

View Set