0% found this document useful (0 votes)
62 views38 pages

Marking Scheme Paper 4 M.T

The document is the mark scheme for the Cambridge International AS & A Level Computer Science Paper 4 Practical for May/June 2023, detailing how marks are to be awarded for various programming tasks. It outlines generic marking principles, specific question requirements, and example code solutions in Java, VB.NET, and Python. The mark scheme serves as a guide for examiners and does not include discussions from the marking meetings.

Uploaded by

Aleena Qayyum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views38 pages

Marking Scheme Paper 4 M.T

The document is the mark scheme for the Cambridge International AS & A Level Computer Science Paper 4 Practical for May/June 2023, detailing how marks are to be awarded for various programming tasks. It outlines generic marking principles, specific question requirements, and example code solutions in Java, VB.NET, and Python. The mark scheme serves as a guide for examiners and does not include discussions from the marking meetings.

Uploaded by

Aleena Qayyum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Cambridge International AS & A Level

COMPUTER SCIENCE 9618/41


Paper 4 Practical May/June 2023
MARK SCHEME
Maximum Mark: 75

Published

This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.

Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.

Cambridge International will not enter into discussions about these mark schemes.

Cambridge International is publishing the mark schemes for the May/June 2023 series for most
Cambridge IGCSE, Cambridge International A and AS Level and Cambridge Pre-U components, and some
Cambridge O Level components.

This document consists of 38 printed pages.

© UCLES 2023 [Turn over


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Generic Marking Principles

These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the
specific content of the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these
marking principles.

GENERIC MARKING PRINCIPLE 1:

Marks must be awarded in line with:

 the specific content of the mark scheme or the generic level descriptors for the question
 the specific skills defined in the mark scheme or in the generic level descriptors for the question
 the standard of response required by a candidate as exemplified by the standardisation scripts.

GENERIC MARKING PRINCIPLE 2:

Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:

Marks must be awarded positively:

 marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond
the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate
 marks are awarded when candidates clearly demonstrate what they know and can do
 marks are not deducted for errors
 marks are not deducted for omissions
 answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the
question as indicated by the mark scheme. The meaning, however, should be unambiguous.

GENERIC MARKING PRINCIPLE 4:

Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.

© UCLES 2023 Page 2 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
GENERIC MARKING PRINCIPLE 5:

Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may
be limited according to the quality of the candidate responses seen).

GENERIC MARKING PRINCIPLE 6:

Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or
grade descriptors in mind.

© UCLES 2023 Page 3 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(a)(i) 1 mark for 1


 1D array with name DataArray (with 25 elements of type Integer)

Example program code:

Java
public static Integer[] DataArray = new Integer[25];

VB.NET

Dim DataArray(24) As Integer

Python
DataArray = [] #25 elements Integer

© UCLES 2023 Page 4 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(a)(ii) 1 mark each to max 4 4


 Opening file Data.txt to read
 Looping through all the 25/EOF …
 … reading each line and storing/appending into array
 Exception handling with appropriate output
 Closing the file (in an appropriate place)

Example program code:

Java
Integer Counter = 0;
try{
Scanner Scanner1 = new Scanner(new File("Data.txt"));
while(Scanner1.hasNextLine()){
DataArray[Counter] = Integer.parseInt(Scanner1.next());
Counter++;
}
Scanner1.close();
}catch(FileNotFoundException ex){
System.out.println("No data file found");
}

VB.NET
try
Dim DataReader As New System.IO.StreamReader("Data.txt")
Dim X As Integer = 0
Do Until DataReader.EndOfStream
DataArray(X) = DataReader.ReadLine()
X = X + 1
Loop
DataReader.Close()
Catch ex As Exception
Console.WriteLine("Invalid file")
End Try

© UCLES 2023 Page 5 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(a)(ii) Python
try:
DataFile = open("Data.txt",'r')
for Line in DataFile:
DataArray.append(int(Line))
DataFile.close()
except IOError:
print("Could not find file")

© UCLES 2023 Page 6 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(b)(i) 1 mark each 3


 Procedure header (and close where appropriate) with (at least) one (integer array) parameter
 Outputting all (25) array elements …
 …on one line

Example program code:

Java
public static void PrintArray(Integer[] DataArray){
String OutputData;
for(Integer X = 0; X < DataArray.length - 1; X++){
OutputData = OutputData + DataArray[X] + " ";
}
System.out.print(OutputData);
}
VB.NET
Sub PrintArray(DataArray)
Dim OutputData As String = "";
For x = 0 To DataArray.length - 1
OutputData = OutputData & DataArray(x) & " "
Next
Console.WriteLine(OutputData)
End Sub

Python
def PrintArray(DataArray):
output = ""
for X in range(0, len(DataArray)):
output = output + str((DataArray[X])) + " "
print(output)

© UCLES 2023 Page 7 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(b)(ii) 1 mark for calling PrintArray with the array as a parameter 1


Example program code:

Java
PrintArray(DataArray);

VB.NET
PrintArray(DataArray)

Python
PrintArray(DataArray)

1(b)(iii) 1 mark for screenshot 1

e.g.

© UCLES 2023 Page 8 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(c) 1 mark each 3


 Function header (and close where appropriate) taking array and search value as parameters
 Looping through each array element and keeping count of the number of times the parameter appears
 Returning the calculated count value

Example program code:

Java
public static Integer LinearSearch(Integer[] DataArray, Integer DataToFind){
Integer Count = 0;
for(Integer x = 0; x < DataArray.length - 1; x++){
if(DataArray[x] == DataToFind){
Count++;
}
}
return Count;
}

VB.NET
Function LinearSearch(DataArray, DataToFind)
Dim Count As Integer = 0
For x = 0 To DataArray.length - 1
If DataArray(x) = DataToFind Then
Count = Count + 1
End If
Next
Return Count
End Function

Python
def LinearSearch(DataArray, DataToFind):
Count = 0
for X in range(0, len(DataArray)):
if(DataArray[X] == DataToFind):
Count +=1
return Count

© UCLES 2023 Page 9 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(d)(i) 1 mark each 4


 Prompt and reading input …
 …with validation for whole number between 0 and 100 inclusive
 Calling LinearSearch() with array and valid data input and storing/using return value
 Output of the message with return value

Example program code:

Java
System.out.println("Enter a number to find");
Integer DataToFind = -1;
Scanner NewScanner = new Scanner(System.in);
while(DataToFind < 0 || DataToFind > 100){
DataToFind = Integer.parseInt(NewScanner.nextLine());
}
Integer NumberTimes = LinearSearch(DataArray, DataToFind);
System.out.println("The number " + DataToFind + " is found " + NumberTimes + " times");

VB.NET
Console.WriteLine("Enter a number to find ")
Dim DataToFind As Integer = -1
Do Until DataToFind >= 0 And DataToFind <= 100
DataToFind = Console.ReadLine()
Loop
Dim NumberTimes = LinearSearch(DataArray, DataToFind)
Console.WriteLine("The number " & DataToFind & " is found " & NumberTimes & " times.")

Python
DataToFind = int(input("Enter a number to find "))
while DataToFind < 0 or DataToFind > 100:
DataToFind = int(input("Enter a number to find "))
NumberTimes = LinearSearch(DataArray, DataToFind)
print("The number", DataToFind, "is found", NumberTimes, "times")

© UCLES 2023 Page 10 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme May/June 2023
PUBLISHED
Question Answer Marks

1(d)(ii) 1 mark for screenshot e.g. 1

© UCLES 2023 Page 11 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(a)(i) 1 mark each to max 4 4


 Class Tree declaration (and end where appropriate)
 All 5 attributes declared as private with correct identifiers and data types
 Constructor header (and end) taking 5 parameters
 Constructor assigns parameters to attributes
e.g.
Java
class Tree{
private String TreeName;
private Integer HeightGrowth;
private Integer MaxWidth;
private Integer MaxHeight;
private String Evergreen;

public Tree(String Name, Integer HGrowth, Integer MaxH, Integer MaxW, String
PEvergreen){
TreeName = Name;
HeightGrowth = HGrowth;
MaxWidth = MaxW;
MaxHeight = MaxH;
Evergreen = PEvergreen;
}}

© Cambridge University Press & Assessment 2024 Page 14 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(a)(i) VB.NET
Class Tree
Private TreeName As String
Private HeightGrowth As Integer
Private MaxHeight As Integer
Private MaxWidth As Integer
Private Evergreen As String
Sub New(Name, HGrowth, MaxH, MaxW, PEvergreen)
TreeName = Name
HeightGrowth = HGrowth
MaxHeight = MaxH
MaxWidth = MaxW
Evergreen = PEvergreen
End Sub
End Class

Python
class Tree:
def __init__(self, Name, HGrowth, MaxH, MaxW, PEvergreen):
self.__TreeName = Name
self.__HeightGrowth = HGrowth
self.__MaxHeight = MaxH
self.__MaxWidth = MaxW
self.__Evergreen = PEvergreen

© Cambridge University Press & Assessment 2024 Page 15 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(a)(ii) 1 mark each 3


 1 get method with no parameter …
 … returning correct attribute
 Remaining 4 correct
e.g.
Java
public String GetTreeName(){
return TreeName;
}
public Integer GetGrowth(){
return HeightGrowth;
}
public Integer GetMaxWidth(){
return MaxWidth;
}
public Integer GetMaxHeight(){
return MaxHeight;
}
public String GetEvergreen(){
return Evergreen;
}

© Cambridge University Press & Assessment 2024 Page 16 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(a)(ii) VB.NET
Function GetTreeName()
Return TreeName
End Function
Function GetMaxHeight()
Return MaxHeight
End Function
Function GetMaxWIdth()
Return MaxWidth
End Function
Function GetGrowth()
Return HeightGrowth
End Function
Function GetEvergreen()
Return Evergreen
End Function

Python
def GetTreeName(self):
return self.__TreeName
def GetMaxHeight(self):
return self.__MaxHeight
def GetMaxWidth(self):
return self.__MaxWidth
def GetGrowth(self):
return self.__HeightGrowth
def GetEvergreen(self):
return self.__Evergreen

© Cambridge University Press & Assessment 2024 Page 17 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
2(b) 1 mark for: 7
 appropriate use of exception handling, with catch and output
1 mark each to max 6
 Function header (and end where appropriate) and declaration of array (of type Tree with min 9 elements)
 Opening text file Trees.txt to read and closing the file
 Reading each line of text (until EOF, or 9 times)
 Splitting each line into the 5 elements
… casting height growth, max height and max width to integers
… creating a new object of type Tree with the 5 values
… storing each object in the array and returning the array
e.g.
Java
public static Tree[] ReadData(){
String TextFile = "Trees.txt";
String[] TempData = new String[5];
Tree[] TreeData = new Tree[20];
String Line;
try{
FileReader f = new FileReader(TextFile);
BufferedReader Reader = new BufferedReader(f);
for(Integer X = 0; X < 9; X++){
try{
Line = Reader.readLine();
TempData = Line.split(",");
TreeData[X] = new Tree(TempData[0], Integer.parseInt(TempData[1]),
Integer.parseInt(TempData[2]), Integer.parseInt(TempData[3]), TempData[4]);
}catch(IOException ex){}
}
try{
Reader.close();
}catch(IOException ex){}

}catch(FileNotFoundException e){
System.out.println("File not found");
}
return TreeData;
}

© Cambridge University Press & Assessment 2024 Page 18 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(b) VB.NET
Function ReadData()
Dim TreeObjects(10) As Tree
Dim TextFile As String = "Trees.txt"
try
Dim FileReader As New System.IO.StreamReader(TextFile)
Dim TreeData(10) As String
Dim TreeSplit() As String
For Count = 0 To 8
TreeData(Count) = FileReader.ReadLine()

Next Count
FileReader.Close()

For X = 0 To 8

TreeSplit = TreeData(X).Split(",")
TreeObjects(X) = New Tree(TreeSplit(0), Integer.Parse(TreeSplit(1)),
Integer.Parse(TreeSplit(2)), Integer.Parse(TreeSplit(3)), TreeSplit(4))
Next X
Catch ex As Exception
Console.WriteLine ("invalid file")
End Try
Return TreeObjects

End Function

© Cambridge University Press & Assessment 2024 Page 19 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(b) Python
def ReadData():
TreeObjects=[]
try:
File = open("Trees.txt")
TreeData = []
TreeData = File.read().split("\n")
SplitTrees = []
for Item in TreeData:
SplitTrees.append(Item.split(","))
File.close()
for Item in SplitTrees:

TreeObjects.append(Tree(Item[0],int(Item[1]),int(Item[2]),int(Item[3]),Item[4]))
except IOError:
print ("invalid file")
return TreeObjects

© Cambridge University Press & Assessment 2024 Page 20 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(c) 1 mark each 4


 Procedure heading (and end) taking one parameter (of type Tree)
and using get methods to access tree name, height, width, growth
 Outputs all 4 attributes (TreeName, MaxHeight, MaxWidth, GetGrowth)
 Checks if it is evergreen…
… correct messages are output if evergreen and otherwise

e.g.
Java
public static void PrintTrees(Tree TreeItem){
String Final = "does not lose its leaves";
if((TreeItem.GetEvergreen()).compareTo("No") == 0){
Final = "loses its leaves each year";
}
System.out.println(TreeItem.GetTreeName() + " has a maximum height " +
TreeItem.GetMaxHeight() + " a maximum width " + TreeItem.GetMaxWidth() + " and grows " +
TreeItem.GetGrowth() + " cm a year. It " + Final);
}

VB.NET
Sub PrintTrees(Item)
Dim Final As String = "does not lose its leaves"
If (Item.GetEvergreen() = "No") Then
Final = "loses its leaves each year"
End If
Console.WriteLine(Item.GetTreeName() & " has a maximum height " &
Item.GetMaxHeight() & " a maximum width " & Item.GetMaxWidth() & " and grows " &
Item.GetGrowth() & "cm a year. It" & Final)
End Sub

© Cambridge University Press & Assessment 2024 Page 21 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(c) Python
def PrintTrees(Item):

Final = "does not lose its leaves"


if Item.GetEvergreen() == "No":
Final = "loses its leaves each year"
print(Item.GetTreeName(), "has a maximum height", Item.GetMaxHeight(),"a maximum
width",Item.GetMaxWidth(),"and grows", Item.GetGrowth(),"cm a year. It",Final)

2(d)(i)  1 mark each 2


 Calling ReadData() and storing/using return value (as array of type Tree)…
…calling PrintTrees() with first object in returned array as parameter

e.g.
Java
Tree[] TreeData = new Tree[20];
TreeData = ReadData();
PrintTrees(TreeData[0]);

VB.NET
Sub Main(args As String())
Dim TreeObjects(10) As Tree
TreeObjects = ReadData()
PrintTrees(Treeobjects(0))
End Sub

Python
TreeObjects = ReadData()
PrintTrees(TreeObjects[0])

2(d)(ii) Screenshot showing output 1

© Cambridge University Press & Assessment 2024 Page 22 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(i) 1 mark each to max 6 6


 Procedure header (and close) taking array of Tree objects as a parameter
and reading evergreen, max height and max width once as input from the user

 Looping through each array object …


 … comparing each width input >= MaxWidth, height input >= MaxHeight
 … comparing each evergreen input with Evergreen
… when all true (all requirements met) - appending object in new array
 Calling PrintTrees() with each valid object
 Outputting suitable message if no trees appropriate

e.g.
Java
public static void ChooseTree(Tree[] Trees){
Scanner scanner = new Scanner(System.in);
System.out.println("Do you want a tree that loses its leaves (enter lose), or keeps
its leaves (enter keep)") ;
String Evergreen = (scanner.nextLine());
System.out.println("What is the maximum tree height in cm");
Integer MaxHeight = Integer.parseInt(scanner.nextLine());
System.out.println("What is the maximum tree width in cm");
Integer MaxWidth = Integer.parseInt(scanner.nextLine());
Tree[] Options = new Tree[20];
String keep;
Tree Selected;
Boolean Valid = false;
if(((Evergreen.toLowerCase()).compareTo("keep") == 0) ||
((Evergreen.toLowerCase()).compareTo("keep leaves") == 0) ||
((Evergreen.toLowerCase()).compareTo("keeps its leaves") == 0)){
keep = "Yes";
}else{
keep = "No";
}
Integer Counter = 0;
for(Integer X = 0; X < 9; X++){

© Cambridge University Press & Assessment 2024 Page 23 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(i) if((Trees[X].GetMaxHeight() <= MaxHeight) && (Trees[X].GetMaxWidth() <=


MaxWidth) && (keep.compareTo(Trees[X].GetEvergreen())==0)){
Options[Counter] = Trees[X];
PrintTrees(Trees[X]);
Counter = Counter + 1;
}
}
if(Counter == 0){
System.out.println("No suitable trees");
}
}

VB.NET
Sub ChooseTree(Trees)
Console.WriteLine("Do you want a tree that loses its leaves (enter lose), or keeps
its leaves (enter keep)")
Dim Evergreen As String = Console.ReadLine()
Console.WriteLine("What is the maximum tree height in cm")
Dim MaxHeight As Integer = Console.ReadLine()
Console.WriteLine("What is the maximum tree width in cm")
Dim MaxWidth As Integer = Console.ReadLine()
Dim Options(0 To 9) As Tree
Dim keep As String
Dim Valid As Boolean
Dim Selected As Tree
If Evergreen.ToLower() = "keep" Or Evergreen.ToLower() = "keep leaves" Or
Evergreen.ToLower() = "keeps its leaves" Then
keep = "Yes"
Else
keep = "No"

© Cambridge University Press & Assessment 2024 Page 24 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(i) End If
Dim count As Integer = 0
For x = 0 To 8
If Trees(x).GetMaxHeight() <= MaxHeight And Trees(x).GetMaxWidth() <= MaxWidth
And keep = Trees(x).GetEvergreen() Then
Options(count) = Trees(x)
PrintTrees(Trees(x))
count = count + 1
End If
Next x
If count = 0 Then
Console.WriteLine("No suitable trees")
End If
End Sub

Python
def ChooseTree(Trees):
Evergreen = input("Do you want a tree that loses its leaves (enter lose), or keeps its
leaves (enter keep)")
MaxHeight = int(input("What is the maximum tree height in cm"))
MaxWidth = int(input("What is the maximum tree width in cm"))
Options = []
if Evergreen.lower() == "keep" or Evergreen.lower() == "keep leaves" or
Evergreen.lower() == "keeps its leaves":
keep = "Yes"
else:
keep = "No"
for Item in Trees:

if Item.GetMaxHeight() <= MaxHeight and Item.GetMaxWidth() <= MaxWidth and keep ==


Item.GetEvergreen():
Options.append(Item)
PrintTrees(Item)
if len(Options) == 0:
print("No suitable trees")

© Cambridge University Press & Assessment 2024 Page 25 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(ii) 1 mark each to max 2


 Taking tree name and initial height as input
 Finding the tree, calculating and outputting the number of years to get to maximum height
VB.NET
Valid = False
Dim Start As Integer
Dim Years As Single
Dim Choice As String
While Valid = False
Console.WriteLine("Enter the name of the tree you want")
Choice = Console.ReadLine()
For X = 0 To count - 1
If Options(X).GetTreeName() = Choice Then
Valid = True
Selected = Options(X)
Console.WriteLine("Enter the height of the tree you would like to start with in
cm")
Start = Console.ReadLine()
Years = (Selected.GetMaxHeight() - Start) / Selected.GetGrowth()
Console.WriteLine("Your tree should be full height in approximately " & Years &
" years")
End If
Next X
End While

© Cambridge University Press & Assessment 2024 Page 26 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(ii) Java
Integer Start;
Float Height;
Float Growth;
Float Years;
while(Valid == false){
System.out.println("Enter the name of the tree you want");
String Choice = scanner.nextLine();
for(Integer X = 0; X < Counter; X++){
if((Options[X].GetTreeName()).compareTo(Choice)==0){
Valid = true;
Selected = Options[X];
System.out.println("Enter the height of the tree you would like to start
with in cm");
Start = Integer.parseInt(scanner.nextLine());
Height = (Selected.GetMaxHeight()).floatValue();
Growth = (Selected.GetGrowth()).floatValue();
Years = (Height - Start) / Growth;
System.out.println("Your tree should be full height in approximately "+
Years + " years");
}
}
}

Python:
Valid = False
while Valid == False:
Choice = input("Enter the name of the tree you want")
for Item in Options:
if Item.GetTreeName() == Choice:
Valid = True
Selected = Item
Start = int(input("Enter the height of the tree you would like to start with in
cm"))
Years = (Selected.GetMaxHeight() - Start)/Selected.GetGrowth()
print("Your tree should be full height in approximately", Years,"years")

© Cambridge University Press & Assessment 2024 Page 27 of 38


9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2024
PUBLISHED
Question Answer Marks

2(e)(iii) 1 mark each 2


 Screenshot shows the user requirements input (height 400, width 200, evergreen) and outputs the correct trees (Blue
conifer and green conifer)
 Screenshot shows the tree selection input (Blue Conifer with height 100) and outputs the correct result (3 years / 3.75
/ 4 years)

© Cambridge University Press & Assessment 2024 Page 28 of 38


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(i) Python

class Character:
#self.XPosition integer
#self.YPosition integer
#self.Name string

def init (self, XPositionP, YPositionP, NameP):


self.XPosition = XPositionP
self.YPosition = YPositionP
self.Name = NameP

© UCLES 2023 Page 26 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(ii) One mark each 3


• 1 get header with no parameter …
• … returning correct value
• 2nd get method

Example program code:

Java

public Integer GetXPosition(){


return XPosition;
}
public Integer GetYPosition(){
return YPosition;
}

VB.NET

Function GetXPosition()
Return XPosition
End Function
Function GetYPosition()
Return YPosition
End Function

Python

def GetXPosition(self):
return self. XPosition

def GetYPosition(self):
return self. YPosition

© UCLES 2023 Page 27 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(iii) One mark each to max 4 4


• 1 set method header (and end where appropriate) with parameter …
• … adding parameter to X/Y Position attribute and storing in the X/Y attribute
• If (resulting value is) more than 10 000 limiting to 10 000 and if less than 0 limiting to 0
• Second correct set method

Example program code:

Java

public void SetXPosition(Integer Value){


XPosition = XPosition + Value;
if(XPosition > 10000){
XPosition = 10000;
}else if(XPosition < 0){
XPosition = 0;
}
}

public void SetYPosition(Integer Value){


YPosition = YPosition + Value;
if(YPosition > 10000){
YPosition = 10000;
}else if(YPosition < 0){
YPosition = 0;
}
}

VB.NET

Function SetXPosition(Value)
XPosition = XPosition + Value
If XPosition > 10000 Then
XPosition = 10000

© UCLES 2023 Page 28 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(iii) ElseIf XPosition < 0 Then


XPosition = 0
End If
End Function
Function SetYPosition(Value)
YPosition = YPosition + Value
If YPosition > 10000 Then
YPosition = 10000
ElseIf YPosition < 0 Then
YPosition = 0
End If
End Function

Python

def SetXPosition(self, Value):


self. XPosition = self. XPosition + Value
if(self.XPosition > 10000):
self.XPosition = 10000
elif self.XPosition < 0:
self.XPosition = 0

def SetYPosition(self, Value):


self.YPosition = self.YPosition + Value
if(self.YPosition > 10000):
self.YPosition = 10000
elif self.YPosition < 0:
self.YPosition = 0

© UCLES 2023 Page 29 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(iv) One mark each 4


• Method header with (string) parameter
• Checking parameter for direction …
• … using SetYPosition() and SetXPosition() correctly …
• … with correct parameters

Example program code:

Java

public void Move(String Direction){


if(Direction.equals("up")){
SetYPosition(10);
}else if(Direction.equals("down")){
SetYPosition(-10);
}else if(Direction.equals("right")){
SetXPosition(10);
}else{
SetXPosition(-10);
}
}

VB.NET

Overridable Sub Move(Direction)


If Direction = "up" Then
SetYPosition(10)
ElseIf Direction = "down" Then
SetYPosition(-10)
ElseIf Direction = "right" Then
SetXPosition(10)
ElseIf Direction = "left" Then
SetXPosition(-10)
End If
End Sub

© UCLES 2023 Page 30 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(a)(iv) Python

def Move(self, Direction):


if(Direction == "up"):
self.SetYPosition(10)
elif(Direction == "down"):
self.SetYPosition(-10)
elif(Direction == "right"):
self.SetXPosition(10)
else:
self.SetXPosition(-10)

3(b) One mark each 2


• New instance of Character created with identifier Jack …
• … correct constructor called and values passed

Example program code:

Java
Character Jack = new Character(50, 50, "Jack");

VB.NET

Dim Jack As Character = New Character(50, 50, "Jack")

Python

Jack = Character(50, 50, "Jack")

© UCLES 2023 Page 31 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(c)(i) One mark each 3


• Class header inheriting from Character
• Constructor taking all 3 parameters …
• … calling parent/super constructor with the 3 parameters

Example program code:

Java
class BikeCharacter extends Character{
public BikeCharacter(Integer XPositionP, Integer YPositionP, String NameP){
super(XPositionP, YPositionP, NameP);
}
}

VB.NET

Class BikeCharacter
Inherits Character

Sub New(XPositionP, YPositionP, NameP)


MyBase.New(XPositionP, YPositionP, NameP)
End Sub
End Class

Python

class BikeCharacter(Character):
def init (self, XPositionP, YPositionP, NameP):
super(). init (XPositionP, YPositionP, NameP)

© UCLES 2023 Page 32 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(c)(ii) One mark each 2


• Method header taking parameter and overriding parent/super Move()
• Correct changes to method to update values by 20

Example program code:

Java

public void Move(String Direction){


if(Direction.equals("up")){
super.SetYPosition(20);
}else if(Direction.equals("down")){
super.SetYPosition(-20);
}else if(Direction.equals("right")){
super.SetXPosition(20);
}else{
super.SetXPosition(-20);
}
}

VB.NET

Overrides Sub
Move(Direction) If
Direction = "up" Then
SetYPosition(20)
ElseIf Direction = "down" Then
SetYPosition(-20)
ElseIf Direction = "right" Then
SetXPosition(20)
ElseIf Direction = "left" Then
SetXPosition(-20)

End If
End Sub

© UCLES 2023 Page 33 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(c)(ii) Python

def Move(self, Direction):


if(Direction == "up"):
super().SetYPosition(20)
elif(Direction == "down"):
super().SetYPosition(-20)
elif(Direction == "right"):
super().SetXPosition(2)
else:
super().SetXPosition(-20)

3(d) One mark each 1


• Declaring new BikeCharacter with correct values e.g.

Java

BikeCharacter Karla = new BikeCharacter(100, 50, "Karla");

VB.NET

Dim Karla As BikeCharacter = New BikeCharacter(100, 50, "Karla")

Python
Karla = BikeCharacter(100, 50, "Karla")

© UCLES 2023 Page 34 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(e)(i) One mark each to max 5 5


• Reading in both values (character and direction) with appropriate prompts
• Character name is validated as e.g. Jack/Karla, and direction is validated as e.g. up/down/left/right
• Calling Move() for the character input, with direction input as a parameter
• Outputting character's new X and Y position in a suitable format …
• … using get methods

Example program code:

Java

System.out.println("Would you like to move Jack or Karla?");


CharacterToMove = (scanner.nextLine()).toLowerCase();
while(CharacterToMove.equals("jack") == false &&
CharacterToMove.equals("karla") == false){
System.out.println("Invalid, try again");
CharacterToMove = (scanner.nextLine()).toLowerCase();
}
System.out.println("Which direction? Up, down, left or right?");
Direction = (scanner.nextLine()).toLowerCase();
while(Direction.equals("up") == false && Direction.equals("down") == false
&& Direction.equals("left") == false && Direction.equals("right")== false){
System.out.println("Invalid, try again");
Direction = (scanner.nextLine()).toLowerCase();
}
if(CharacterToMove.equals("jack")){
Jack.Move(Direction);
System.out.println("Jack's new position is X = "
+ Jack.GetXPosition() + " Y = " + Jack.GetYPosition());
}else{
Karla.Move(Direction);
System.out.println("Karla's new position is " +
Karla.GetXPosition()
+ " " + Karla.GetYPosition());
}

© UCLES 2023 Page 35 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(e)(i) VB.NET

Console.WriteLine("Would you like to move Jack or Karla?")


CharacterToMove = Console.ReadLine.ToLower()
While CharacterToMove <> "jack" And CharacterToMove <> "karla"
Console.WriteLine("Invalid try again")
CharacterToMove = Console.ReadLine
End While
Console.WriteLine("Which direction? Up, down, left or right")
Direction = Console.ReadLine.ToLower()
While Direction <> "up" And Direction <> "down" And Direction <> "left" And Direction <>
"right"
Console.WriteLine("Invalid try again")
Direction = Console.ReadLine
End While
If CharacterToMove = "jack"
Then Jack.Move(Direction)
Console.WriteLine("Jack's new position is X = " & Jack.GetXPosition & " Y = " &
Jack.GetYPosition)
Else
Karla.Move(Direction)
Console.WriteLine("Karla's new position is X = " & Karla.GetXPosition & " Y = " &
Karla.GetYPosition)
End If
Console.WriteLine("Would you like to Continue? Enter True to continue, or anything else to
quit")

© UCLES 2023 Page 36 of 37


9618/41 Cambridge International AS & A Level – Mark Scheme October/November 2023
PUBLISHED
Question Answer Marks

3(e)(i) Python

CharacterToMove = input("Would you like to move Jack or Karla?").lower()


while CharacterToMove != "jack" and CharacterToMove != "karla":
CharacterToMove = input("Invalid try again")
Direction = input("Which direction? Up, down, left or right?")
while Direction != "up" and Direction != "down" and Direction != "left" and Direction !=
"right":
Direction = input("Invalid try again")
if CharacterToMove == "jack":
Jack.Move(Direction)
print("Jack's new position is X =", Jack.GetXPosition(), "Y =", Jack.GetYPosition())
else:
Karla.Move(Direction)
print("Karla's new position is X =", Karla.GetXPosition(), "Y =", Karla.GetYPosition())

3(e)(ii) One mark for each test 2

© UCLES 2023 Page 37 of 37

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy