User interface language: English | Español

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

Question

A hotel chain has a loyalty scheme in which customers are awarded 1000 points for each day they stay in one of their hotels. With these points, customers can achieve one of three status levels: Gold, Silver or Bronze. The level will determine the extra services to which they are entitled.

The total number of points collected during the current year will determine which of the three status levels they are assigned for the following year: For example only the points collected in 2018 will determine the status level for 2019.

Occasionally, new customers receive additional bonus points as part of a promotion.

The Points class keeps details of the points and status levels of each customer.

public class Points
{
private String memberId; // id of the hotel customer
private int totalPoints; // this year's points
private int bonusPoints; // any bonus points given to this year's new member
private String statusNow; // current(this year's)status
private String statusNextYear; // following year's status
private Visits[] allVisits = new Visits[366];//details of each visit
// during this year
int y; // number of visits this year

public
Points(String id) // constructor for new member
{
memberId = id;
bonusPoints = 0;
y = 0;
statusNow = "Bronze";
}

//constructor for new member given bonus points (valid for current year only)
public Points(String id, int bp)
{
memberId = id;
bonusPoints = bp; // multiples of 1000 - maximum number is 5000
y = 0;
statusNow = "Bronze";
}

// all the accessor and mutator methods are present but not shown

public
Visits getAllVisits(int v)
{
return allVisits[v];
}

public void
addVisit(Visits v) // adds a new Visit object to the array
{
allVisits[y] = v;
y = y + 1;
}

isGold() {code missing}
calculateTotalPoints(){code missing}
daysMissing(){code missing}
}

The instance variables in the Points class are preceded by the modifier private. The choice of modifier affects the way in which these variables are accessed or used.

The customers will be assigned one of three levels for the following year (Gold, Silver or Bronze) depending upon the current year’s total points as follows.

In 2018, Tim became a member for the first time and was awarded a bonus of 1000 points. So far, in 2018, Tim has stayed three times at one of these hotels. The first visit lasted 2 days, the second visit lasted 1 day and the third visit lasted 6 days.

The different Points objects are stored in an array which is declared globally in the main (driver) class as follows: Points[] allPoints = new Points[10000];

With the use of two examples other than private, outline how the choice of this modifier affects the way in which these variables are accessed or used.

[4]
a.

With reference to the two methods with the same name in the Points class, explain the OOP feature that makes it possible to successfully implement either of these methods.

[4]
b.

State the status level that Tim has been assigned, for 2019, following these visits.

[1]
c.

State how an individual object can be identified using this array.

[1]
d.

The attribute statusNow is assigned its correct value at the beginning of every year for existing members. It cannot be changed during the year.

Construct the method isGold() in the Points class, which will return whether the current status is “Gold”.

[3]
e.

Markscheme

public;
Allows access to variables from outside of the class/unlimited access;

protected;
Allows access to variable from within the package (project) in which they are created/subclasses;

final;
Prevents variables from being modified;

static;
Refers to variables that act on the class as a whole (and not on individual objects);

Note:

a.

The OOP feature shown in the constructors (accept the 2 signatures) is overloading (accept polymorphism);
The constructor methods have a different number / type of parameters / different parameters;
The method calling the constructor / compiler will determine which of these methods is selected;
By matching up with the parameters;

b.

Silver;

c.

Through the use of the (appropriate) array index / appropriate code description;

Example:

Individual object = allVisits[individual object’s location]

d.
public boolean isGold()
{
return (statusNow.equals("Gold"); // allows =
}

Award marks as follows:
Signature;
Correct comparison (allow use of getStatusNow());
Return (that matches the signature – allow FT);

Note:

e.

Examiners report

[N/A]
a.
[N/A]
b.
[N/A]
c.
[N/A]
d.
[N/A]
e.

Syllabus sections

Option D: Object-oriented programming » D.3 Program development
Show 45 related questions
Option D: Object-oriented programming

View options