User interface language: English | Español

Date May 2018 Marks available 2 Reference code 18M.2.HL.TZ0.18
Level HL Paper 2 Time zone no time zone
Command term Outline Question number 18 Adapted from N/A

Question

Full details of the customers are stored as objects of the Customer class. This class is partially shown below:

public class Customer
{
private String memberId;
private String email; //email address (assume only 1 per customer)

public
Customer(String a, String b)
{
memberId = a;
email = b;
}

public
String getMemberId()
{
return memberId;
}

public
String getEmail()
{
return email;
}
}

The objects can be accessed through the linked list allCustomers which is declared in the main (driver) class as follows:

LinkedList<Customer> allCustomers = new LinkedList<Customer>()

Outline why a linked list structure has been chosen for allCustomers.

[2]
a.

Construct the method goldMails() that will return an ArrayList containing the email addresses of all current “Gold” members. You should make use of any previously defined methods.

[6]
b.

Markscheme

Example 1:
The link list will enable space to be allocated dynamically/will only take up the space required;
Because the number of customers is unknown / customers may join or leave the loyalty scheme during the year;
Example 2:
Customers / objects / nodes can be easily added or deleted;
So customers may join or leave the loyalty scheme during the year;

a.
public ArrayList goldMails()
{
ArrayList al = new ArrayList(); // Allow use of <String> identifier
int s = allCustomers.size();
int x = 0;
while(!(allPoints[x] == null)) // Allow(allPoints[x]!=null)
{
if (allPoints[x].isGold())
{
String a = allPoints[x].getMemberId();
for (int y = 0; y < s; y++)
{
String b = allCustomers.get(y).getMemberId();
if (a.equals(b)) // allow =
al.add(allCustomers.get(y).getEmail());
}
}
x = x + 1
}
return al;
}

Award marks as follows:
Declaring a new ArrayList (with or without the String identifier);
Looping through the allPoints array;
Testing for “Gold”;
Loping through the allCustomers linked list (using the size or an iterator);
Correct check for identical ids;
Adding the email to the ArrayList;
Returning the arraylist;

Note:

b.

Examiners report

[N/A]
a.
[N/A]
b.

Syllabus sections

Option D: Object-oriented programming » D.4 Advanced program development
Show 33 related questions
Option D: Object-oriented programming

View options