User interface language: English | Español

Date November 2019 Marks available 8 Reference code 19N.2.SL.TZ0.12
Level SL Paper 2 Time zone no time zone
Command term Construct Question number 12 Adapted from N/A

Question

When the number of customers in the supermarket is low, some check-out counters will close. When there are many customers waiting, a new check-out counter will open.

When a new check-out counter opens, some customers from the nearest line will choose to move their carts to this check-out counter.

For this simulation, the assumption is made that every second cart in the old line will move to the new line and the other carts will remain in the original line.

Outline why the variable active in the UML of the class POSline was defined as a boolean data type.

[2]
a.

Construct the code for a method split (part of the class POSsystem), that takes an existing, non-empty POSline as a parameter. It should copy every second cart from the original line into a new line. Afterwards it should delete every second cart from the original line.

An example call in POSsystem would be: POSline number2 = split(number1), where number1 is an existing POSline.

You may use any method declared or developed.

[8]
b.

As a result of the simulation, the company has decided to create a new POS system for their supermarkets.

There have been discussions about adapting existing open source code when developing modules of the new POS system.

Describe two ethical issues that may arise if modules of the new POS system are developed from open source code.

[4]
c.

Markscheme

Award [2 max]
active indicates that a POS counter is either open (true) or closed (false);
boolean uses the least memory space / one bit to represent this data;

a.

Award [8 max]
Award [1] for a correct method header;
Award [1] for correctly declaring and returning a new POSline variable;
Award [1] for attempting to use modulo division / declaring and initialising a flag;
Award [1] for a loop with one correct terminal condition, including increment of i;
Award [1] for the second correct loop condition;
Award [1] for correctly checking that i is odd / checking and setting the flag;
Award [1] for copying a cart from the original line;
Award [1] for correctly adding every second cart to the new line;
Award [1] for a reasonable attempt at removing every second cart;
Award [1] for correctly removing every second cart from the original line;

public POSline split(POSline oldLine){
POSline newLine = new POSline();
Cart temp; // optional, see below
int i=0;
boolean remove=false;
while((i<20)&&(oldLine.getLine(i)!=null)){
if (remove) {
temp = oldLine.getLine(i); // can be combined
newLine.joinLine(temp);
}
remove = !remove;
i++;
}
remove=false;
while((i<20)&&(oldLine.getLine(i)!=null)){
if (remove) {
temp = oldLine.leaveLine(i)); // shifts carts
remove = !remove;
}
else{
i++;
}
}
return newLine;
}

Example answer using modulo division (MOD):

public POSline split(POSline oldLine){
POSline newLine = new POSline();
int i=0;
while((i<20)&&(oldLine.getLine(i)!=null)){
if (i%2==1) {
newLine.joinLine(oldLine.getLine(i));//combined
}
i++;
}
while(i>0){ // must be reverse order
if (i%2==1) {
temp = oldLine.leaveLine(i);
}
i--;
}
return newLine;
}

Example answer using a flag that combines both copy and remove actions (not anticipated):

public POSline split(POSline oldLine){
POSline newLine = new POSline();
int i=0;
boolean flag=false;
while((i<20)&&(oldLine.getLine(i)!=null)){
if (flag) {
newLine.joinLine(oldLine.leaveLine(i));
}
else i++;
flag = !flag;
}
return newLine;
}
b.

Award [4 max].
(Any) software can be considered as a form of Intellectual property;
Company should consider whether there is a need to acknowledge the work of other programmers (don’t accept answers talking about plagiarism);

Open source software may have undergone many changes from the original;
So adequate testing of the final product must take place;
to prevent any malfunction that will affect their customers;

The company will be promoting the spread of open source software;
Helping to break the monopolies of the major IT companies;
To the benefit of people / countries with reduced financial resources;

The use of open-source software means that the code can (more easily) be read/understood/ hacked by others;
Leading to possible data breaches for their customers;

Code may contain malware;
Leading to possible data breaches for their customers;

Using open-source software results in less work for programmers;
This affecting their livelihood;

Mark as [2] and [2].

Notes:
Award 2 marks for a valid issue if a detailed discussion has been provided
- Only give credit for issues that have some ethical connection

c.

Examiners report

Most referred to the fact that only two states were possible but did not link this into saving of memory.

a.

The most difficult questions on the paper for SL candidates. This was a good test for the better programmers, but many candidates struggled with the logic. Two separate methods of processing every other value were seen in the answers: the use of the modulo function and incrementing the loop by 2. The use of previously defined methods was suggested, and many candidates did just that.

b.

The candidates appeared unprepared for this question but most described at least one valid ethical issue.

c.

Syllabus sections

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

View options