?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Customer Class Constructor Method

APCSA-4KPEKF

Given the following class:

public class Customer 
{
    // The following are instance variables for a new customer:
    private int custNum; 
    private String firstName;
    private String lastName;
    private String homePhone = "";
    private double totPurchaseAmt = 0;
    private int[] orders;    // list of customer order numbers

    // other data and methods not shown
}

Which of the following constructor methods would correctly initialize the instance variables in this class?

A
public Customer(int cNum, String fName, String lName, 
                String hPhone, double totPurch, int ords)
{
    custNum = cNum;
    firstName = fName;
    lastName = lName;
    homePhone = hPhone;
    totPurchaseAmt = totPurch;
    orders = ords;
}
B
public Customer(int cNum, String fName, String lName, 
                int hPhone, double totPurch, int[] ords)
{
    custNum = cNum;
    firstName = fName;
    lastName = lName;
    homePhone = hPhone;
    totPurchaseAmt = totPurch;
    orders = ords;
}
C
public Customer(int custNum, String firstName, String lastName, 
         String homePhone, double totPurchaseAmt, int[] orders)
{
    custNum = this.custNum;
    firstName = this.firstName;
    lastName = this.lastName;
    homePhone = this.homePhone;
    totPurchaseAmt = this.totPurchaseAmt;
    orders = this.orders;
}
D
public Customer(int custNum, String firstName, String lastName, 
          String homePhone, double totPurchaseAmt, int[] orders)
{
    this.custNum = custNum;
    this.firstName = firstName;
    this.lastName = lastName;
    this.homePhone = homePhone;
    this.totPurchaseAmt = totPurchaseAmt;
    this.orders = orders;
}
E
public Customer(int custNum, String firstName, String lastName, 
          String homePhone, double totPurchaseAmt, int[] orders)
{
    custNum = custNum;
    firstName = firstName;
    lastName = lastName;
    homePhone = homePhone;
    totPurchaseAmt = totPurchaseAmt;
    orders = orders;
}