Method Signatures FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A harbor class includes this header:

public static double waitTime(int boats, boolean fog)

(a) Write the method signature. (b) Name three pieces of the header that are not part of the signature. (c) Explain why waitTime(boolean, int) would be a different signature.

Question 2 of 5

A buoy API documents only these methods.

Method Signature Purpose
ping ping() flashes once
ping ping(int) flashes that many times
tag tag(int, boolean) records channel and lamp
waitTime waitTime(double) returns minutes for a distance in km

A program already has int km = 3 stored, but the keeper needs the minutes to travel 3.0 kilometers. (a) Identify the method that should be called and write a legal call. (b) Explain why ping(int) is the wrong choice. (c) Explain how the ordered parameter type list guided the selection.

Question 3 of 5

The methods below are in the same class.

public static void bump(int tide)
{
    tide = tide + 5;
}
public static int bumpAndReturn(int tide)
{
    tide = tide + 5;
    return tide;
}

For each snippet, state the displayed value and explain it. (a) int mark = 20; bump(mark); System.out.print(mark); (b) int mark = 20; mark = bumpAndReturn(mark); System.out.print(mark);

Question 4 of 5

The methods below are in the same class.

public static int pack(int crates)
{
    return crates * 2;
}
public static int pack(int crates, int extra)
{
    return crates * 2 + extra;
}

(a) Which overload does pack(6) use, and what value is returned? (b) Which overload does pack(6, 2) use, and what value is returned? (c) Explain how Java chooses between the two methods.

Question 5 of 5

The methods below are in the same class.

public static int horn()
{
    System.out.print("B");
    return 3;
}

System.out.print("A");
System.out.print(horn());
System.out.print("C");

(a) State the displayed text. (b) Explain when control leaves the caller and when it returns. (c) Explain why the 3 appears in the output.