AP CSA UC Scout Semester 1 Final

0.0(0)
studied byStudied by 2 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/262

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

263 Terms

1
New cards

Check which of the following are examples of computational thinking. Mark all that apply.

Mapping out a trip to Florida

Choosing the movie to watch at the cinema

Deciding what to wear to the prom

2
New cards

Check which of the following are examples of computational thinking. Mark all that apply.

Choosing a college

Shopping for a car

3
New cards

All of the following are included in the the process of computational thinking except

Coding

4
New cards

Check which of the following are examples of computational thinking. Mark all that apply.

Shopping for a bicycle

Planning what to do with friends on the weekend

Baking a cake

5
New cards

Scenario: Consider operating a car as part of a computer program. Turning the key to start a car is a form of

Abstraction

6
New cards

Consider the following code segment.

System.out.println("How many chucks\n");
System.out.print("could a woodchuck chuck\n");
System.out.print("if a woodchuck could chuck ")
System.out.print("wood?");

What is printed as a result of executing the code segment? Choose the best answer.

Nothing - compiler error

7
New cards

Consider the following code segment.

System.out.println("\"Observe good faith and justice \ntoward all nations.\"");

System.out.print("George Washington");

What is printed as a result of executing the code segment? Choose the best answer.

"Observe good faith and justice

toward all nations."

George Washington

8
New cards

Consider the following code segment.

System.out.println("What we");System.out.println("think, we become.");System.out.print("Buddha");

What is printed as a result of executing the code segment? Choose the best answer.

What we

think, we become.

Buddha

9
New cards

Consider the following code segment.

System.out.print("count down");System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");

What is printed as a result of executing the code segment? Choose the best answer.

count down4321 liftoff!

10
New cards

Consider the following code segment.

System.out.print("Oh, what fun");System.out.print(" it is")System.out.print(" to learn Java!");

What is printed as a result of executing the code segment? Choose the best answer.

Nothing - compiler error

11
New cards

Consider the following code segment.

System.out.print("Oh, ");System.out.println("happy");System.out.print("happy");System.out.print("day!");

What is printed as a result of executing the code segment? Choose the best answer.

Oh, happy

happyday!

12
New cards

Consider the following code segment.

System.out.print("a");System.out.println("b");System.out.print("c");System.out.print("d");

What is printed as a result of executing the code segment? Choose the best answer.

ab

cd

13
New cards

Consider the following code segment.

System.out.print("\"Yesterday you said tomorrow.\n");System.out.print("Just do it.\"\n");System.out.print("- Nike");

What is printed as a result of executing the code segment? Choose the best answer.

"Yesterday you said tomorrow.

Just do it."

- Nike

14
New cards

Consider the following code segment.

System.out.print(5);System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");

What is printed as a result of executing the code segment? Choose the best answer.

54321 liftoff!

54321liftoff!

54321 liftoff!

54321Liftoff!

54321 liftoff!

15
New cards

Consider the following code segment.

System.out.print('count down');System.out.print("4");System.out.print("3");System.out.print("2");System.out.print("1");System.out.print(" liftoff!");

What is printed as a result of executing the code segment? Choose the best answer.

54321liftoff!

54321 liftoff!

Nothing - compiler error

54321liftoff!

54321 liftoff!

16
New cards

Consider the following code segment where x is a local variable:

int x;System.out.println(x);

What would be the output? (Choose the best answer.)

None, runtime error

x

None, Compiler error

0

None, Compiler error

17
New cards

In Java, boolean information can be...

zero or one

true or false

any number

all of these

true or false

18
New cards

Of the following declarations, which are declared properly? Choose all that apply.

String set = "on ready";

char go = "F"

boolean ready = false;

char go = 'F';

String set = "on ready";

boolean ready = false;

char go = 'F';

19
New cards

What is the size in bytes for a long data type?

8

4

1

2

8

20
New cards

Of the following declarations, which are declared properly? Choose all that apply.

String a = null;

String c = "a";

String d = "happy";

String b = "";

String a = null;

String c = "a";

String d = "happy";

String b = "";

21
New cards

What is the default value of a boolean data type?

false

empty

0

true

false

22
New cards

What can be stored in a char data type?

true

'A'

"aa"

"name"

'A'

23
New cards

What is the default value of a double data type?

0.0

0

empty

1

0.0

24
New cards

In Java, boolean information can be...

zero or one

any number

true or false

all of these

true or false

25
New cards

Given the following declarations:

int i = 12; short s = 35;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

f = i * 2;

24.0

26
New cards

What is the default value of an int data type?

empty

0

0.0

1

0

27
New cards

Which value below falls within the range of an int? Choose all that apply.

1,000,000

1

0

1,000,000,000,000

1,000,000

1

0

28
New cards

Which value below falls within the range of an short? Choose all that apply.

1000

0

100

130

1000

0

100

130

29
New cards

What is the size in bytes for a short data type?

2

1

8

4

2

30
New cards

A code segment (not shown) is intended to determine the number of players whose average score in a game exceeds 0.5. A player's average score is stored in avgScore, and the number of players who meet the criterion is stored in the variable count.

Which of the following pairs of declarations is most appropriate for the code segment described?

double avgScore;boolean count;

int avgScore;int count;

double avgScore;double count;

double avgScore;int count;

double avgScore;

int count;

31
New cards

Consider the following code segment.

System.out.print("One"); // Line 1System.out.print("Two"); // Line 2System.out.print("Three"); // Line 3System.out.print("Four"); // Line 4

The code segment is intended to produce the following output, but does not work as intended.

OneTwoThreeFour

Which of the following changes can be made so that the code segment produces the intended output?

Changing print to println in line 1 only

Changing print to println in lines 1, 2, 3, and 4

Changing print to println in line 2 only

Changing print to println in line 3 only

Changing print to println in line 2 only

32
New cards

In this course, to gather input for a user, we used a class from the Java APi named the ____________ class.

Scanner

Scan

Input

Sc

Scanner

33
New cards

Consider the following code segment.

System.out.print("");System.out.println("");System.out.println("*");System.out.print("***");

What is printed as a result of executing the code segment?

**********

**********

**********

**********

***

***

****

34
New cards

Consider the following code segment.

System.out.print(); // Line 1System.out.print(""); // Line 2System.out.println(); // Line 3System.out.println("*"); // Line 4

The code segment is intended to produce the following output, but may not work as intended.

***

Which line of code, if any, causes an error?

Line 3

Line 4

The code segment works as intended

Line 2

Line 1

Line 1

35
New cards

Consider the following code segment.

System.out.print(5);System.out.print(4);System.out.print(3);System.out.print(2);System.out.print(1);System.out.print(" liftoff!");

What is printed as a result of executing the code segment? (Choose the best answer.)

54321liftoff!

5 4 3 2 1 liftoff!

54321 liftoff!

54321 Liftoff!

THIS ONE IS THE CORRECT ONE IF SHOWN BEFORE

54321 liftoff!

36
New cards

Consider the following code segment.

System.out.print("AP");System.out.println();System.out.println("CS");System.out.print("A");

What is printed as a result of executing the code segment?

APCSA

APCSA

AP CSA

APCSA

AP

CS

A

37
New cards

Consider the following code segment.

import java.util.Scanner public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter your name:" ); String name = input.nextLine(); System.out.print("Hello, " name); }}

What will be the output if the user enters Jack?

Hello Jack

Hello, Jack

There is a compiler error because input is a keyword and we cannot use it as a variable

There is a compiler error because there is no concatenation operator to join "Hello" and the value of name.

There is a compiler error because there is no concatenation operator to join "Hello" and the value of name.

38
New cards

Consider the following code segment.

System.out.print(I do not fear computers. ); // Line 1System.out.println(I fear the lack of them.); // Line 2System.out.println(--Isaac Asimov); // Line 3

The code segment is intended to produce the following output but may not work as intended.

I do not fear computers. I fear the lack of them.--Isaac Asimov

Which change, if any, can be made so that the code segment produces the intended output?

In line 1, print should be changed to println.

In lines 2 and 3, println should be changed to print.

In lines 1, 2, and 3, the text that appears in parentheses should be enclosed in quotation marks.

No change is needed; the code segment works correctly as is.

In lines 1, 2, and 3, the text that appears in parentheses should be enclosed in quotation marks.

39
New cards

Consider the following code segment.

System.out.print("Hello System.out.println");System.out.print("!!!");

What is printed as a result of executing the code segment?

Hello System.out.println!!!

Hello!!!

Nothing is printed because the text "System.out.println" cannot appear inside a print statement.

Hello !!!

Hello System.out.println!!!

40
New cards

If an int variable age holds the value 5, what is its value after the following statement is executed?

age = age * 4;

If it shows an error, just type error.

20

41
New cards

Which of the following expressions evaluate to 4 ?

I. 7+ 10 % 13II. (7 + 10) % 13III. 6 - 2 % 13

II & III only

I & II only

I only

I, II, & III

II & III only

42
New cards

What is the result of 19 % 5 when evaluated in a Java expression?

If it shows an error, just type error.

4

43
New cards

What is the result of 13 / 4 when evaluated in a Java expression?

If it shows an error, just type error.

3

44
New cards

What would be the output of the following code?

int x = 110;int y = 3;x %= y;System.out.println(x);

5

2

107

3

2

45
New cards

x and y are declared as integer variables.You are given the following expression:

x >= y

Which of these expressions is the opposite of the above expression and has valid syntax?

x < y

There's not enough information to determine this.

x =< y

x <= y

x == y

x < y

46
New cards

If an int variable weight currently holds the value 150, what is its value after the following statement is executed?

weight -= 27;

If it shows an error, just type error.

123

47
New cards

What will be printed after the following statements are executed?

int length;length = 11; // 11length = 3; length = length;length /= 50;System.out.println(length);

If it shows an error, just type error.

21

48
New cards

If an int variable weight currently holds the value 150, what is its value after the following statement is executed?

weight -= 27;

If it shows an error, just type 'error.'

123

49
New cards

Assume that you are given the following declarations:

int num = 0;double val = 0.0;num = 9 % 6 / 4 - 4;

Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'

-4

50
New cards

What is the result of

17 % 5

when evaluated in a Java expression?

If it shows an error, just type 'error.'

2

51
New cards

Assume that you are given the following declarations:

int num = 0;double val = 0.0;num = 2 % 6 / 2 - 4;

Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'

-3

52
New cards

What will be printed after the following statements are executed?

int length;length = 11; // 11length = 3; length = length;length /= 50;System.out.println(length);

If it shows an error, just type error.

21

53
New cards

What would be the output of the following code?

int input = 5;int output = 3;input++;output += input;System.out.println(output);

9

10

11

12

9

54
New cards

If an int variable age holds the value 4, what is its value after the following statement is executed?

age = age * 7;

If it shows an error, just type 'error.'

28

55
New cards

What would be the output of the following code?

int x = 10;int y = 5;x %= y;System.out.println(x);

0

10

1

5

0

56
New cards

Consider the following code segment, which is intended to print the digits of the two-digit int number num in reverse order. For example, if num has the value 53, the code segment should print 35. Assume that num has been properly declared and initialized.

/ missing code /

System.out.print(onesDigit);System.out.print(tensDigit);

Which of the following can be used to replace / missing code / so that the code segment works as intended?

int onesDigit = num % 10;int tensDigit = num / 10;

int onesDigit = num / 10;int tensDigit = num % 10;

int onesDigit = 10 / num;int tensDigit = 10 % num;

int onesDigit = num % 100;int tensDigit = num / 100;

int onesDigit = num % 10;

int tensDigit = num / 10;

57
New cards

Assume that you are given the following declarations:

int num = 0;double val = 0.0;val = 11 % 6 / 2.0 - 1;

Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error.'

1.5

58
New cards

Which of the following returns the correct average when 3 values had been added to an integer total?

(double) total / 3;

(double) (total / 3);

(int) total / 3;

total / 3;

(double) total / 3;

59
New cards

Given the following code segment, what is the value of b when it finishes executing?

double a = 9.6982;int b = 12;b = (int) a;

9.6982

10

12

9

9

60
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

f = 3.14;

0.5357143

61
New cards

Assume that you are given the following declarations:

int num;double val;val = 17 / 2.0 + 4;

Show the value that will be stored in the variable on the left. If the expression causes an error, just type 'error'.

12.5

62
New cards

Which of the following returns the correct average when 3 values had been added to an integer total?

(double) total / 3;

total / 3;

(double) (total / 3);

(int) total / 3;

(double) total / 3;

63
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

m = i + 1;

16

64
New cards

The following code is illegal. Rewrite the code using an integer cast to make it legal.

double d = 187.2;int j = d;

int j = 187.2;

double d = d + 187.2;

int j = (int) d;

int double d = 187.2;

int j = (int) d;

65
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

i = f * 2;

5.0

66
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

f = (float) 3.14;

3.14

67
New cards

Consider the following code segment

int count = 5;double multiplier = 2.5;int answer = (int) (count multiplier);answer = (answer count) % 10;System.out.println(answer);What is printed as a result of the code segment?

0.5

2.5

12.5

0

0

68
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

i = s + 1;

26

69
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

i = (int) m + 1;

51

70
New cards

What makes a constant in Java?

The keyword constant

The keyword final

The keyword static

Writing it in all capitals

The keyword final

71
New cards

Given the following declarations:

int i = 15; short s = 35;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

i = s + 3;

38

72
New cards

If an integer variable diameter currently holds the value 5, what is its value after the following statement is executed?

diameter = diameter * 4;

If it shows an error, just type error.

20

73
New cards

What is the default value of an int data type?

empty

0.0

1

0

0

74
New cards

What would be the output of the following code?

int x = 10;int y = 5;x %= y;System.out.println(x);

1

5

10

0

0

75
New cards

What would be the output of the following code?

int x = 110;int y = 3;x %= y;System.out.println(x);

2

5

107

3

2

76
New cards

What would be the output of the following code?

int x = 10;int y = 5;x--;y += x;System.out.println(y);

15

14

12

11

14

77
New cards

Consider the following code segment, which is intended to print the digits of the two-digit int number num in reverse order. For example, if num has the value 53, the code segment should print 35. Assume that num has been properly declared and initialized.

/ missing code /

System.out.print(onesDigit);System.out.print(tensDigit);

Which of the following can be used to replace / missing code / so that the code segment works as intended?

int onesDigit = num % 10;int tensDigit = num / 10;

int onesDigit = 10 / num;int tensDigit = 10 % num;

int onesDigit = num / 10;int tensDigit = num % 10;

int onesDigit = num % 100;int tensDigit = num / 100;

int onesDigit = num % 10;

int tensDigit = num / 10;

78
New cards

Which of the following expressions evaluate to 4?

7+ 10 % 13

(7 + 10) % 13

6 - 2 % 13

1

1 and 2

2 and 3

All (1, 2, and 3)

2 and 3

79
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

i = s + 1;

26

80
New cards

Question 172 / 2 pts

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

d = f * i + 1;

38.5

81
New cards

Given the following declarations:

int i = 15; short s = 25;long m = 50;float f = 2.5f;double d = 0.25;

Show the value that will be stored in the variable on the left after the expression below is executed. If it shows an error, just type error.

s = (short)5;

5

82
New cards

The following code is illegal. Rewrite the code using an integer cast to make it legal.

double d = 187.2;int j = d;

double d = d + 187.2;

int j = 187.2;

int j = (int) d;

int double d = 187.2;

int j = (int) d;

83
New cards

What specifies the behavior of objects in a Java class?

methods

class

object

attributes

methods

84
New cards

Consider the following code. What would be the output?

public class Question { private int num = 20; public static void main(String args[]) { Question q1 = new Question(); System.out.println(q1.num); }}

20

Nothing output; compiler error

q1.num

"20"

20

85
New cards

You can only have one constructor method in your class.

True

False

false

86
New cards

A programmer has created an Employee class. The class contains variables to represent the following.

A String variable called name to represent the name of the employee

An int variable called age to represent the age of the employee

A String variable called gender to represent the gender of the employee

A String variable called race to represent the race of the employee

The object person will be declared as type Employee.

Which of the following descriptions is accurate?

An attribute of the person object is name.

An instance of the Employee object is person.

An instance of the person class is Employee.

An attribute of the age object is int.

An attribute of the person object is name.

87
New cards

Which of the following is a proper constructor method for a Train class?

public Train() { };

public class Train() { };

public String Train() { };

private Train() { };

public Train() { };

88
New cards

What is the correct way to create an object with the reference variable fluffy of the Cat class?

new Cat fluffy;

Cat new = Cat fluffy();

Cat fluffy = Cat();

Cat fluffy = new Cat();

Cat fluffy = new Cat();

89
New cards

A class has a default constructor when it is first created.

True

False

true

90
New cards

A student has created a Person class. The class contains variables to represent the following:

A String variable called name to represent the name of a Person object

An int variable called age to represent the age of a Person object

A String variable called gender to represent the gender of a Person object

The object is declared as type Person and has the reference variable p1. Which of the following descriptions is accurate?

An attribute of the Person object is String.

An instance of the Person class is name.

An attribute of the Person instance is p1.

An attribute of the Person instance is age.

An attribute of the Person instance is age.

91
New cards

A student has created a Cat class. The class contains variables to represent the following:

A String variable called breed to represent the breed of a Cat object

An int variable called age to represent the age of a Cat object

A String variable called name to represent the name of a Cat object

The object is declared as type Cat and has the reference variable pet. Which of the following descriptions is accurate?

An instance of the pet class is Cat.

An instance of the Cat class is pet.

An attribute of the name object is String.

An attribute of the Cat instance is pet.

An instance of the Cat class is pet.

92
New cards

What are the data or properties for an object in Java?

attributes

methods

object

class

attributes

93
New cards

Consider the following method.

public double oneMethod(int a, boolean b) { / implementation not shown / }

Which of the following lines of code, if located in a method in the same class as oneMethod, will compile without error?

double result = oneMethod(0, false);

int result = oneMethod(2, false);

double result = oneMethod(2.5, true);

int result = oneMethod(2.5, true);

double result = oneMethod(0, false);

94
New cards

When you write a method, the heading is always in the following order:

method name - return type - parameters

return type - method name - parameters

parameters - return type - method name

the order doesn't matter

return type - method name - parameters

95
New cards

Consider the following method.

public void doSomething() { System.out.println("Let's do something!");}

Each of the following statements appears in a method in the same class as doSomething().

Which of the following statements are valid uses of the method doSomething()?

doSomething();

String output = doSomething();

System.out.println(doSomething());

I and II only

II only

I and III only

I only

I only

96
New cards

Consider the following methods, which appear in the same class.

public int function1(int i, int j) { return i + j;}public int function2(int i, int j) { return j - i;}

Which of the following statements, if located in a method in the same class, will initialize the variable x to 11?

int x = function2(3, 1) + function1(4, 5);

int x = function2(4, 5) + function1(1, 3);

int x = function1(3, 1) + function2(4, 5);

int x = function1(4, 5) + function2(1, 3);

int x = function1(4, 5) + function2(1, 3);

97
New cards

Consider the following methods, which appear in the same class.

public void slope(int x1, int y1, int x2, int y2) { int xChange = x2 - x1; int yChange = y2 - y1; printFraction(yChange, xChange);}public void printFraction(int numerator, int denominator) { System.out.print(numerator + "/" + denominator);}

Assume that the method call slope(1, 2, 5, 10) appears in a method in the same class. What is printed as a result of the method call?

2/1

8/4

5/1

4/8

8/4

98
New cards

Consider the following method.

public double myMethod(int a, boolean b){ / implementation not shown / }

Which of the following lines of code, if located in a method in the same class as myMethod, will compile without error?

double result = myMethod(0, false);

int result = myMethod(2.5, true);

double result = myMethod(true, 10);

int result = myMethod(2, false);

double result = myMethod(0, false);

99
New cards

Consider the following method.

public void doSomething() { System.out.println("Something has been done");}

Each of the following statements appears in a method in the same class as doSomething. Which of the following statements are valid uses of the method doSomething?

doSomething();

String output = doSomething();

System.out.println(doSomething());

I only

I, II, and III

I and III

I and II

I only

100
New cards

Consider the following method.

public double oneMethod(int a, boolean b){ / implementation not shown / }

Which of the following lines of code, if located in a method in the same class as oneMethod, will compile without error?

double result = oneMethod(false, 1);

int result = oneMethod(9.2, false);

double result = oneMethod(10, true);

int result = oneMethod(22, false);

double result = oneMethod(10, true);