Académique Documents
Professionnel Documents
Culture Documents
Level Three
Answer TWO questions from the remaining THREE questions, questions 2 to 4 which are
worth 30 marks each. If you answer all THREE questions from questions 2 to 4, marks will
ONLY be awarded for your TWO best answers.
1. a. Explain how Java offers support for contracts via the use of assertions,
and state the advantages and disadvantages of using them. Your answer
should include an example of an assertion.
[8 marks]
(ii) Study the code below. Will it compile? Explain your answer in
detail. If you don’t think the code will compile, identify a
change you could make so that it would compile. Line numbers
are included to assist you with referring to specific code in your
explanation.
[6 marks]
1. class W {}
2. class Y {}
3. class X extends W {}
4. class Z extends Y {}
5. public class Substitute {
6. public static void main(String[] args) {
7. W w;
8. Y y;
9. X x;
10. Z z;
11. x = new X();
12. z = new Z();
13. y = z;
14. x = w;
15. }
16. }
[10 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 2 of 6
Approved
d. The Front Controller design pattern is one of the core J2EE design
patterns used in many systems. Critically discuss this design pattern
outlining the advantages and disadvantages of it.
[10 marks]
[5 marks]
class Q2b {
public static void main(String[] args) {
int x = 3;
int y = x;
x = 4;
System.out.println("y = " + y);
Point p = new Point(3.5, 4.5);
Point q = p;
q.x = 13.0;
System.out.println("point x is " + p.x);
}
}
class Point {
double x; double y;
Point(double x, double y) { this.x=x; this.y=y; }
}
[3 marks]
c) Discuss two ways in which Java threads can be created and run.
Explain, with an appropriate application example for each, how Java
threads can be used in the following situations. You answer should also
include potential problems:
i) The use of “synchronized” to manage thread safety when
parallel processing with shared critical data;
ii) Prioritisation of threads.
[14 marks]
Page 3 of 6
Approved
class Q3b
{
public static void main(String[] args)
{
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = a / b;
System.out.println("The answer is " + c);
}
}
[12 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 4 of 6
Approved
[7 marks]
[3 marks]
iii) In the application shown in part i), when the user clicks the Car
button, the Cars count is to be increased by 1, and when the user
clicks the Van button, the Vans count is to be increased by 1.
Describe how this may be achieved with reference to the event
handling mechanism of Java. Again, a description in English only is
required – do NOT write detailed Java code.
[5 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 5 of 6
Approved
// test 1
calc = new Calculator(1.5, 3.5);
System.out.println("Test 1. Expected value 5.0: " +
calc.operate(1));
// test 2
calc = new Calculator(5.4, 4.4)
System.out.println("Test 2. Expected value 1.0: " +
calc.operate(2));
}
}
[7 marks]
[8 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 6 of 6