Print Options

Card layout:

← Back to notecard set|Easy Notecards home page

Instructions for Side by Side Printing
  1. Print the notecards
  2. Fold each page in half along the solid vertical line
  3. Cut out the notecards by cutting along each horizontal dotted line
  4. Optional: Glue, tape or staple the ends of each notecard together
  1. Verify Front of pages is selected for Viewing and print the front of the notecards
  2. Select Back of pages for Viewing and print the back of the notecards
    NOTE: Since the back of the pages are printed in reverse order (last page is printed first), keep the pages in the same order as they were after Step 1. Also, be sure to feed the pages in the same direction as you did in Step 1.
  3. Cut out the notecards by cutting along each horizontal and vertical dotted line
Print these notecards...Print as a list

77 notecards = 20 pages (4 cards per page)

Viewing:

AP COMPSCI FINAL STUDY GUIDE

front 1

Refer to the following method.

public static int mystery(int n)
{
if (n == 1)
return 3;
else
return 3 * mystery(n - 1);
}

What value does mystery(1) return?

back 1

3

front 2

If a, b, and c are integers, which of the following conditions is sufficient to guarantee that the expression

a < c || a < b && !(a == c)

evaluates to true?

back 2

a < c

front 3

When will the result be equal to 3?

public static int whatIsIt(int x, int y)
{
int result = 0;
if (x > y)
result = 4;
else
result = 3;

return result;
}

back 3

x <= y

front 4

What is the output of the following Java code?

int x = 0;
if (x < 0)
System.out.print("One ");
System.out.print("Two ");
System.out.print("Three");

back 4

Two Three

front 5

Consider the method
public String mystery(String s)
{
String s1 = s.substring(0,1);
String s2 = s.substring(1, s.length() - 1);
String s3 = s.substring(s.length() - 1);

if (s.length() <= 3)
return s3 + s2 + s1;

else
return s1 + s2 + s3;
}

What is the output of
System.out.println(mystery("DELIVER"));

back 5

DELIVER

front 6

1. Suppose x = 2 and y = 3. If the statement x *= y; is executed once, what is the value of x?

A. 2
B. 3
C. 5
D. 6

back 6

D

front 7

2. Based on the code below:

String sentence;
String str1, str2, str3;
int length1, length2;

sentence = "Today is Wednesday.";

str1 = sentence.substring(9, 18);
str2 = str1.substring(0, 3);
str3 = sentence.replace('d', '*');

length1 = sentence.length();
length2 = str1.length();

System.out.print(str3);

A. To*ay is We*nes*ay.
B. Today * Wednesday
C. Today is Wednesday
D. **d** ** **d***d**

back 7

A

front 8

3. Consider the following method definition:

public static void printTopHalf()
{
}

The word static :

A. is called the return type
B. is called the method name
C. surrounds the parameter list
D. is needed if the method is called from main()
E. surrounds the method body
F. is known as the access specifier

back 8

D

front 9

4. When you define the procedure, create a ______________ for each value you want to pass into the procedure.

A. instance variable
B. local variable
C. formal parameter
D. actual parameter

back 9

C

front 10

5. Look at the following use of the substring() method:

String word = "Hello World!";
String subs = word.substring(1,2);

The String subs will contain:

A. "H"
B. "He"
C. "el"
D. "e"

back 10

D

front 11

6. When defining a function, (unlike a procedure), you must specify a ____________.

A. return statement
B. access specifier
C. parameter list
D. return type

back 11

D

front 12

7. Consider the following code segment:

if (n != 0 && x / n > 100)
statement1;
else
statement2;

If n is of type int and has a value of 0 when the segment is executed, what will happen?

A. An ArithmeticException will be thrown.
B. A syntax error will occur.
C. statement1, but not statement2, will execute.
D. statement2, but not statement1, will execute.
E. Neither statement1 nor statement2 will be executed; control will pass to the first statement following the if statement.

back 12

D

front 13

8. Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi".

|| EXAMPLES:
|| makeAbba("Hi", "Bye") → "HiByeByeHi"
|| makeAbba("Yo", "Alice") → "YoAliceAliceYo"
|| makeAbba("What", "Up") → "WhatUpUpWhat"

public String makeAbba(String a, String b)
{
String result = "";
result = _________________

return result;
}

What would result need to be in order to finish this function?

A. a + b + b +a;
B. "Hello " + name + "!";
C. first + last + last + first;
D. b + a + a + b;
E. last + first + first + last;

back 13

A

front 14

The elements inside the class body are surrounded with, or delimited by:
A braces{ }
B parenthesis ( )
C quotations " "
D brackets [ ]

back 14

A

front 15

In a main method definition, the symbols appearing inside the ( ) are called the:

A. getters
B. parameter list
C. methods
D. setters

back 15

B

front 16

Which of these words that can appear in a Java program are not a reserved word? *Hint: It does not show up in blue text in Dr. Java.
A. int
B. out
C. class
D. void

back 16

B

front 17

Here is a portion of the source code for a computer program:
69 6D 70 6F 72 74 20 6A-61 76 61 2E 61 77 74 2E 3B 0D 0A 69 6D 70 6F-72 74 20 6A 61 76 61 2E 61 77 74 2E 65 6E-74 2E 2A 3B 0D 69 6D

This program is an example of _________________.

A. human readable
B. machine language
C. HLL
D. assembly language

back 17

B

front 18

True or False: The following statement, written in the interactions pane, will compile and print to the console.

System.out.println("said Sally. "I've said so." See?);

back 18

False

front 19

Which of these must appear outside the body of a class?

A. variable definitions
B. instance variables
C. import statements
D. constructors

Response Feedback: The import statement cannot go inside the body of the class. Output statements must appear in a method. Comments can appear anywhere. Variable definitions can go inside a method or inside a class.

back 19

C

front 20

Which of these is a legal (that is, syntactically correct) Java class name?

A. U2
B. 2U
C. U-2
D. 2_U

Response Feedback: While letters, digits and underscores are legal in identifiers, you cannot start with a digit. You also cannot have spaces or hyphens in an identifier. That leaves U2.

back 20

A

front 21

Write the main method heading: It must be exactly as Java needs it to be for your code to compile.

Hint: *No hint this time.

public static void main (String[] args)
public static void main(String[ ] args)
public static void main(String[] args)
public static void main (String[ ] args)

back 21

public static void main (String[] args)
public static void main(String[ ] args)
public static void main(String[] args)
public static void main (String[ ] args)

front 22

The following line of code is going to print out what type of value?

System.out.print("575");

A. double
B. int
C. String

back 22

C

front 23

What is the output of the following code segment?

int myAge = 63;

int kathysAge = myAge;

kathysAge = 60;

System.out.print(myAge);

A. 63
B. myAge
C. 60
D. kathysAge

back 23

A

front 24

1. Evaluate the following expression. Make sure that your answer is correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0.
13 + Math.abs(-7) - Math.pow(2.0, 3) + 4

back 24

16.0

front 25

2. Evaluate the result from evaluating the following integer expression. Make sure that your answer is the correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0.
26 % 10 % 4 * 2

back 25

4

front 26

3. In the assignment statement below, what is the purpose of the (double) ?
int x = 3, y = 2;
double z = (double) x / y;

A. To double the amount of the answer, like multiplying by 2.
B. To make sure that the result of the division is a decimal number.
C. To round the answer to the nearest integer.
D. To round the answer to the nearest tenth.

back 26

B

front 27

4. Which of the following code fragments will cause an error?
A. String greeting = "Hello, Kevin!";
System.out.print(greeting);
B. int luckyNumber;
System.out.println(luckyNumber);
C. System.out.println("Hi " + 5);

back 27

B

front 28

5. The statement System.out.print ("No" + (2 + 3) + "way"); produces the output:
A. No5way
B. No 2 3 way
C. No23way
D. None. Illegal statement

back 28

A

front 29

6. In Java, Scanner is a class in which package?
A. java.lang
B. java.text
C. java.util
D. java.io

back 29

C

front 30

7. Evaluate the result from evaluating the following integer expression. Make sure that your answer is the correct type. For instance, if the answer is 2 and the type is int, then you should enter 2. If the answer is 2, and the type is double, then enter 2.0.
(12 + 4) / 4 * 2

back 30

8

front 31

8. Which of the following statements correctly creates a Scanner object for keyboard input?
A. Keyboard scanner = new Keyboard(System.in);
B. Scanner keyboard = new Scanner(System.in);
C. Scanner cin = new Scanner(System.Keyboard);
D. Scanner keyboard(System.in);

back 31

B

front 32

9. Which of the following is not a primitive data type?
A. int
B. String
C. double

back 32

B

front 33

10. What's the result of the following code snippet?
public static void main(String[ ] args)
{
double bottles;
double bottles_volume = bottles * 2;
System.out.println(bottle_volume);
}
A. 0
B. 1
C. 2
D. compile-time error

back 33

D

front 34

1. Refer to the following code fragment:

double answer = 12 / 7;
System.out.println("12 / 7 = " + answer);

The output is

12 / 7 = 1

The programmer intends the output to be

12 / 7 = 1.7142857142857142

Which of the following replacements for the first line of code will not fix the problem?

A. double answer = 12.0 / 7;
B. double answer = 12 / 7.0;
C. double answer = 12.0 / 7.0;
D. int answer = (12 / 7);

back 34

D

front 35

2. Which one of the following is a correct method of declaring and initializing an double variable with name crossett?
A. crossett = 30;
B. crossett = double 30;
C. double crossett = 30;
D. double crossett;

back 35

C

front 36

3. The statement System.out.print("No" + "2 + 3" + "way"); produces the output:
A. No5way
B. No2 + 3way
C. NoNowaywayway
D. No+6+way

back 36

B

front 37

4. What value is stored in result if:

int result = 10 - 2 % 2;

A. 10
B. 1
C. 4
D. 0

back 37

A

front 38

5. True or False: All of the following statements are true.
In Java, 12 % 5 and 12 / 5 have the same answer.
The names int and double describe the type of variable being initialized or declared.

back 38

True

front 39

6. Which of the following variable names is an example of a constant?
A. milesPerHour
B. MILES_PER_HOUR
C. MilesPerHour
D. final

back 39

B

front 40

7. Refer to the following code fragment below:

public String yourName = "Kevin";

The name yourName refers to:
A. the type of variable
B. it's ability to be used by other methods.
C. the name of the variable.
D. the value of the variable

back 40

C

front 41

8. Define: Define Concatenation operator.

back 41

+

front 42

9. What is the name of the following Scanner object?
Scanner cin = new Scanner(System.in);

back 42

cin

front 43

10. In a variable definition, the kind of value stored inside is called its:
A. method
B. type
C. class
D. assignment

back 43

B

front 44

When a Java string does not have surrounding double quotes, what type of error occurs?

back 44

Compile-time error

front 45

Text, like everything else in your computer, is stored as raw binary numbers. To treat those numbers as characters, they must be encoded. The encoding scheme used in Java is called:

back 45

Unicode

front 46

Programs that are designed to "work for you", carrying out a task you specify, are known as

back 46

application programs

front 47

The devices that feed data and programs into computers are called ______.

back 47

Input Devices

front 48

If your java source code program compiles, but displays an error message when you run it, then it must have a:

back 48

runtime error

front 49

What is the computer component that stores program instructions during a program execution?

back 49

memory

front 50

Four common predefined escape sequences
\t - Tab (numeric value 9, Ctrl+I or Tab)
\n - Newline (numeric value 10, Ctrl+J)

Place a double quote inside a string:
System.out.print("then she said, \"Hello\"");

Place a backslash inside a string
System.out.println("C:\\Windows\\my.ini");

back 50

Know the slide 29 on Week 1.2.

front 51

Each memory cell has a unique location in main memory, called the _________.

back 51

address

front 52

Which of the following will correctly check to see if the variable x is equal to 5?

back 52

if (x == 5)

front 53

What is the output of the following code snippet, if the input is 25?

public static void main(String[ ] args)

{

Scanner cin = new Scanner(System.in);

System.out.print(“Please enter a number: “);

int i = cin.nextInt( );

if(i > 24)

{

i++;

}

else

{

i--;

}

System.out.println(i);

}

back 53

26

front 54

What is the output of the following Java code?

int x = 0;

if(x < 1)

System.out.print(“One “);

System.out.print(“Two “);

System.out.print(“Three”);

back 54

One Two Three

front 55

What is the value of the price variable after the following code snippet is executed?

int price = 42;

if(price < 45)

{

price = price + 10;

}

if(price < 30)

{

price = price * 2;

}

if(price < 100)

price = price - 20;

}

back 55

32

front 56

What is the output of the following code snippet?

public static void main(String[ ] args)

{

int num = 100;

if(num != 100)

{

System.out.println(“Not 100”);

}

else

{

System.out.println(“100”);

}

}

back 56

100

front 57

What is the output of the following code snippet?

public static void main(String[ ] args)

{

double income = 45000;

double cutoff = 55000;

double min_income = 30000;

if(min_income > income)

{

System.out.println(“Minimum income requirements not met.”);

}

if(cutoff < income)

{

System.out.println(“Income requirement is met.”);

}

else

{

System.out.println(“Maximum income limit is exceeded.”);

}

}

back 57

Maximum income limit is exceeded.

front 58

What is the output of the following code snippet?

public static void main(String[ ] args)

{

int s1 = 20;

if(s1 < 20)

{

System.out.print(“1”);

}

if(s1 <= 40)

{

System.out.print(“2”);

}

if(s1 > 20)

{

System.out.print(“3”);

}

}

back 58

2

front 59

What is the syntax error in the following method definition?

public static area(double r)

{

double a;

a = 3.14 * r * r;

return r * r;

}

back 59

The method does not specify a return type.

front 60

When you try to convert String data to numeric values, using the Integer.parseInt() or Double.parseDouble() functions on a String that is improperly formatted (containing spaces, commas, or other illegal characters) you will get:

back 60

a NumberFormatException

front 61

Consider the following method definition:

public static void printTopHalf()

{

}

The word printTopHalf :

back 61

is called the method name

front 62

If you use the String searching functions to search for a particular character or substring, and the value you’re searching for is not found, the methods will return:

back 62

-1

front 63

Which of the following represents correct /* implementation */ code for the constructor in the card class?

back 63

mySuit = suit;

myValue = value;

front 64

1. Consider this hierarchy, in which Novel and Textbook are subclasses of Book.

Which of the following is a true statement about the classes shown?

back 64

Each of the classes - Book, Novel, and Textbook - can have a method computeShelfLife, whose code in Book and Novel is identical, but different from the code in Textbook.

front 65

A programmer is designing a program to catalog all books in a library. She plans to have a Book class that stores features of each book: author, title, isOnShelf, and so on, with operations like getAuthor, getTitle, getShelfInfo, and setShelfInfo. Another class, LibraryList, will store an array of Book objects. The LibraryList class will include operations such as listAllBooks, addBook, removeBook, and searchForBook. The programmer plans to implement and test the Book class first, before implementing the LibraryList class. The programmer’s plan to write the Book class first is not an example of

back 65

top-down development.

front 66

Which statement about the Quadrilateral class is true?

back 66

The perimeter and area methods are abstract because there’s no suitable default code for them.

front 67

A programmer plans to write a program that simulates a small bingo game (no more than six players). Each player will have a bingo card with 20 numbers from 0 to 90 (no duplicates). Someone will call out numbers one at a time, and each player will cross out a number on his card as it is called. The first player with all the numbers crossed out is the winner. In the simulation, as the game is in progress, each player’s card is displayed on the screen.

The programmer envisions a short driver class (sometimes called test class) whose main method has just two statements:

BingoGame b = new BingoGame( );

b.playBingo( );

The BingoGame class will have several objects: a Display, a Caller, and a PlayerGroup. The PlayerGroup will have a list of Players, and each Player will have a BingoCard.

The relationship between the PlayerGroup and Player classes is an example of

back 67

composition

front 68

Which statement about the Quadrilateral class is true?

back 68

The method getLabels is wrong and should be getLabels().

front 69

Which represents correct /* implementation code */ for the Rectangle constructor?

I super(labels, topLeft, botRight);

II super(labels);

this.myTopLeft = topLeft;

this.myBotRight = botRight;

III super(labels);

myTopLeft = topLeft;

myBotRight = botRight;

back 69

II and III only

front 70

Consider an ArrayList<Quadrilateral> quadList whose elements are of type Rectangle, Parallelogram, or Square.

Refer to the following method, writeAreas:

What is the effect of executing this method?

back 70

The appropriate area method for each quad in quadList will be determined.

front 71

Refer to the definitions of ClassOne and ClassTwo below.

Consider the following declarations in a client class. You may assume that ClassOne and ClassTwo have default constructors.

ClassOne c1 = new ClassOne();

ClassTwo c2 = new ClassTwo();

Which of the following method calls will cause an error?

I. c1.methodTwo();

II. c2.methodTwo();

III. c2.methodOne();

back 71

I only

front 72

Which of the following will execute without throwing an exception?

I. String s = null;

String t = "";

if (s.equals(t))

System.out.println("empty strings?");

II. String s = "holy";

String t = "moly";

if (s.equals(t))

System.out.println("holy moly!");

III. String s = "holy"

String t = s.substring(5);

System.out.println(s + t);

back 72

II only

front 73

A programmer plans to write a program that simulates a small bingo game (no more than six players). Each player will call out numbers one at a time, and each player will cross out a number on his card at it is called. The first player with all the numbers crossed out is the winner. In the simulation, as the game is in progress, each player's card is displayed on the screen.

The programmer envisions a short driver class whose main method has just two statements:

BingoGame b = new BingoGame();

b.playBingo();

The BingoGame class will have several objects: a display, a Caller, and a PlayerGroup.

The PlayerGroup will have a list of Players, and each Player will have a BingoCard.

The relationship between the PlayerGroup and Player classes is an example of

back 73

composition.

front 74

Which of the following correctly initializes an array arr to contain four elements each with value 0?

I. int[] arr = {0, 0, 0, 0};

II int[] arr = new int[3];

III int[] arr = new int [4];

for (int i = 0; i < arr.length; i++)

arr[i] = 0;

back 74

I and III only

front 75

Consider the following method.

public static int mystery(int[] arr)

{

int x = 0;

for (int k = 0; k < arr.length; k = k + 3)

x = x + arr[k];

return x;

}

Assume that the array nums has been declared and initialized as follows.

int[] nums = {3, 6, 1, 0, 4, 1, 2};

What value will be returned as a result of the call mystery(nums) ?

back 75

5

front 76

Consider the following method.

public ArrayList<Integer> mystery(int n)

{

ArrayList<Integer> seq = new ArrayList<Integer>();

for (int k = 0; k <= n; k++)

seq.add(new Integer(k * k + 3));

return seq;

}

Which of the following is printed as a result of executing the following statement?

System.out.println(mystery(6));

back 76

[3, 4, 7, 12, 19, 28, 39]

front 77

Consider the following code segment.

int x = 7;

double y = 3;

if ((x < 10) && (y < 0))

System.out.println("Value is: " + x * y);

else

System.out.println("Value is: " + x / y);

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

back 77

Value is: 2.3333333