?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Get Last Customer Order From Integer Array

APCSA-VD6VEF

Given the following class:

public class Customer 
{
    private int custNum; 
    private int[] orders;    // list of customer order numbers

    // other instance variables, constructors and methods not shown
}

Note that orders will contain at least one customer order number and it will always be full of customer order numbers. Which of the following methods would return the last customer order number for this customer?

I.

    public int getLastCustOrderNum()
    {
        return orders[orders.length-1];
    }

II.

    public int getLastCustOrderNum()
    {
        int i=0;
        for ( ; i<orders.length; i++);
        return orders[i-1];
    }

III.

    public int getLastCustOrderNum()
    {
        int order=0;
        for int i=0; i<orders,length; i++)
        {
            order = orders[i];
        }
        return order;
    }
A

I only.

B

III only.

C

I and II only.

D

I and III only.

E

I, II, and III.