logo

Exam Paper: Programming 2

This is an examination paper for the module Programming 2 at Northumbria University.

17 Pages3422 Words494 Views
   

Added on  2022-11-26

About This Document

This exam paper is for the Programming 2 module. It covers topics like testing, inheritance, exceptions, and files. The paper includes questions on white box testing criteria, equivalence partitioning, abstract classes, interfaces, and exception handling. It also includes a question on the File class in Java. Download the paper now from Desklib.

Exam Paper: Programming 2

This is an examination paper for the module Programming 2 at Northumbria University.

   Added on 2022-11-26

ShareRelated Documents
EXAMINATION PAPER
Module Title: Programming 2
Module Code: KV4001
Module Tutor: XXXX
Examination set by: XXXX
Academic Year: XXXX
Month: XXXX
Time Allowed: 3 Hours
INSTRUCTIONS TO CANDIDATES
Please read carefully before you begin your examination.
This is an open notes exam.
You are allowed to use up to 6 sides (3 sheets) of handwritten A4 notes to help
you during the examination. Word-processed material will be removed by the
invigilators! Each page should have your Northumbria ID at the top of the page
& clearly show page ‘x’ of ‘y’ pages. No other material (books, other loose
paper, etc.) is allowed. These must be handed in with your exam paper and
answer booklet(s) at the end of your exam.
No additional materials are allowed.
There is one section in this exam paper.
There are four questions on this exam paper .
Answer three questions ONLY. If you answer four questions only the first three
will be marked.
Marks for each question part are indicated after each part.
Total marks per question are shown below each question.
This examination is marked out of 60 marks.
It is worth 70 % of the total marks for this module.
Exam Paper: Programming 2_1
PLEASE NOTE: You should only answer the number of questions required
above. If you answer more than this, your answers will be marked in the order
they appear in your answer sheets, up to and including the required number.
Any additional answers will not be marked. Please cross out any work that you
do not wish the marker to consider. Please check your work to ensure you
have answered the correct number of questions and they are clearly
numbered.
You must abide by the University’s regulations on academic misconduct.
Formal enquiry proceedings will be instigated if there is any suspicion of
misconduct in your work.
1. Testing
(a
)
The following are possible White Box “criteria” that may be used to
guide the selection test cases:
For each criteria give a brief definition and discuss its relative
strengths and weaknesses. You must illustrate your answer with
short sections of Java code
Statement Coverage;
Statement coverage is said to ensure that each statement in
the code is executed at-least once.
Advantage:
1) It is used to measure the code quality
2) It tests whether the code performs the task correctly
Disadvantage:
1) False condition is not tested
2) Does not understand logical operator functions
3) It does not test whether loop terminates or not
Code:
public class Test{
public static void main(String args[]){
System.out.println(“Numbers”);
int n= 10;
if(n%2==0){
for(int i=0;i<5;i++){
System.out.println(i);
}
}
else{
for(int i=5;i<10;i++){
System.out.println(i);
}
}
}
}
Description:
(8 Marks)
Exam Paper: Programming 2_2
Statement coverage does not test the else part of code and does
not check termination condition in for loop inside the if condition.
Branch Coverage;
Branch coverage is said to ensure that all possible branch i.e.
all code statements in both true and false branches of decisions will
be tested at-least once
Advantages:
1) It checks whether the code statement in all branches are
executed
2) It ensures that no branch leads to abnormal behaviour of
program execution.
Disadvantages:
1) It tests the condition in the branch statement in short circuit
manner. It ignores the branches in Boolean expression.
Code:
public class Test{
public static void main(String args[]){
System.out.println(“Numbers”);
int n1= 10;
int n2= 20;
if((n1%2==0) || (n2%3==0)){
for(int i=0;i<5;i++){
System.out.println(i);
}
}
else{
for(int i=5;i<10;i++){
System.out.println(i);
}
}
}
}
Description:
Branch coverage test both if and else part of code and checks for
termination condition in for loops. In branch condition only n1%2==0
is executed other condition n2%3==0 is not executed.
Multiple Condition Coverage.
In Multiple Condition coverage, a decision with multiple
condition is tested such that all possible of combination of condition
is tested.
Advantages:
1) It tests all possible combination of Boolean expression
Disadvantages:
1) It is difficult to determine the minimum set of test cases
required for a very complex Boolean condition expression.
Code:
Exam Paper: Programming 2_3
public class Test{
public static void main(String args[]){
System.out.println(“Numbers”);
int n1= 10;
int n2= 20;
if((n1%2==0) || (n2%3==0)){
for(int i=0;i<5;i++){
System.out.println(i);
}
}
else{
for(int i=5;i<10;i++){
System.out.println(i);
}
}
}
}
Description:
Multiple condition coverage forms a truth table to test all possible
condition of boolean expression((n1%2==0) || (n2%3==0)). It tests all
possible combination.
(b
)
A Black Box approach to generating test cases is based on
“Equivalence Partitioning”
(i) Explain what we mean by Equivalence Partitioning. (2 Marks)
Solution:
Equivalence partitioning is a software testing technique which
divides input data into partitions such that at-least one test cases can
be derived from each partition.
(ii) Define the equivalence classes for each of the following:
An integer in the range 1 to 100
Solution:
Valid Equivalence Classes: [1-100]
Invalid Equivalence Classes: [greater than 100]
Invalid Equivalence Classes: [less than 1]
An input consisting of between 2 and 4 names
Solution:
2D Shapes = {Square, Rectangle, Cirlce} (4 marks)
Valid Equivalence Classes: [Square]
Exam Paper: Programming 2_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Measurement Techniques for Business Performance | Bank of Maldives
|19
|5746
|1

Time Constrained Assessment for BSc (Hons) Civil Engineering
|21
|4563
|74

4UDBE - Dynamic Business Environments
|19
|5317
|541

5UIBP Level 5 Innovation and Business Performance
|15
|5404
|866

5UEFM Level 5 Effective Financial Management
|22
|5908
|1273

Target Costing in Food Manufacturing Industry
|12
|4949
|42