AP Java Unit 3 Quiz

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

C

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

A

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

D

What is a return value?
A:
The value that a method prints to the screen.
B:
The value that is inputted to a method.
C:
The value that a user inputs to a program.
D:
The value that a method outputs.

D

What does void mean?
A:
Void means that a method returns any value.
B:
Void means that a method takes no parameters.
C:
Void means that a method returns no value.
D:
Void means that a method can take any parameter.

C

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

C

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

D

What will the value of yourBankAccount be after the method call?
depositMoney(yourBankAccount, 1000000);
EXAMPLE:
int yourBankAccount = 0;
public void depositMoney(int bankAccount, int deposit)
{
bankAccount += deposit;
}
A:
1000000
B:
0
C:
100000
D:
The

B

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.
A:

D

What will this method call print?
patternGrid(3,4,'#');
EXAMPLE:
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();
}
}
A:
####

A

What would this method call output?
myMethod(830)
EXAMPLE:
public int myMethod(int num)
{
while(num / 10 >= 10)
{
num /= 10;
}
return num;
}
A:
830
B:
30
C:
0
D:
8
E:
83

E

What is the return value of this method call?
someWhereInTheMiddle(188603)
EXAMPLE:
public static String someWhereInTheMiddle(int number)
{
String stringNum = "" + number;
int middle = stringNum.length()/2;
if(stringNum.length() % 2 == 1)
{
return stringN

D

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

B

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

B

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

A

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

D

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

C

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

B

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

D

What will this method call output?
mysteryMethod("Karel The Dog", 'e');
EXAMPLE:
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;
}
A:
1
B:
2
C:
3
D:
4

C

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

B

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

B

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

A

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

D

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

D

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

C

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

A

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

D

What is a return value?
A:
The value that a method prints to the screen.
B:
The value that is inputted to a method.
C:
The value that a user inputs to a program.
D:
The value that a method outputs.

D

What does void mean?
A:
Void means that a method returns any value.
B:
Void means that a method takes no parameters.
C:
Void means that a method returns no value.
D:
Void means that a method can take any parameter.

C

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

C

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

D

What will the value of yourBankAccount be after the method call?
depositMoney(yourBankAccount, 1000000);
EXAMPLE:
int yourBankAccount = 0;
public void depositMoney(int bankAccount, int deposit)
{
bankAccount += deposit;
}
A:
1000000
B:
0
C:
100000
D:
The

B

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.
A:

D

What will this method call print?
patternGrid(3,4,'#');
EXAMPLE:
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();
}
}
A:
####

A

What would this method call output?
myMethod(830)
EXAMPLE:
public int myMethod(int num)
{
while(num / 10 >= 10)
{
num /= 10;
}
return num;
}
A:
830
B:
30
C:
0
D:
8
E:
83

E

What is the return value of this method call?
someWhereInTheMiddle(188603)
EXAMPLE:
public static String someWhereInTheMiddle(int number)
{
String stringNum = "" + number;
int middle = stringNum.length()/2;
if(stringNum.length() % 2 == 1)
{
return stringN

D

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

B

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

B

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

A

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

D

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

C

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

B

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

D

What will this method call output?
mysteryMethod("Karel The Dog", 'e');
EXAMPLE:
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;
}
A:
1
B:
2
C:
3
D:
4

C

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

B

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

B

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

A

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

D

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

D