Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Level Three
_________________________________________________________________
Object Oriented Software Development
COMP1307
APPROVED
ii) Explain whether the clone() method in the above code satisfies
the canonical form of classes for this example and why.
[6 marks]
Page 2 of 7
APPROVED
Question 2 continued
b) You are given the following code for the Employee class:
import java.util.*;
Page 3 of 7
APPROVED
Question 2 continued
4. a) Study the program code below, which involves the display of four
buttons:
import java.awt.*;
import javax.swing.*;
public class MyFrame extends JFrame {
public static void main(String[] args) {
MyFrame f = new MyFrame();
f.setSize(250, 350);
Container c = f.getContentPane();
c.setLayout(new GridLayout(2,1));
for (int i=0; i < 2; i++) {
JPanel pan = new JPanel();
pan.setBackground(i == 0 ? Color.lightGray : Color.white);
for (int j=0; j < 2; j++) {
JButton b = new JButton("Button number: " + i + " " + j);
pan.add(b);
}
c.add(pan);
}
f.setVisible(true);
}
}
Explain how this program executes when the code is compiled and run,
and sketch the appearance of the output.
[8 marks]
Question 4 continued on next page
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 4 of 7
APPROVED
Question 4 continued
c) Discuss how the event related to a button click can be handled, and add
code to the program listed in part a) so that if a button is clicked, a
message is displayed stating which button was clicked. (The message
could be displayed using the System.out.println() method).
[6 marks]
d) Explain, with some example code, how a nested class can be used to
handle the button click event and display the message “A button has
been clicked” to the user. (The message could be displayed using the
System.out.println() method).
[7 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 5 of 7
APPROVED
6. a) Study the code for the Java program below and answer the questions
about it which follow:
public class JQ {
public static void main (String [] a) {
int array1 [] = {12, 13, 14};
int array2 [] = {12, 13, 14};
(i) Write down exactly what output you think the program will
produce when it is executed. Explain exactly why you think the
program will produce the output that you predict.
[8 marks]
(ii) Write a new method of class JQ called sum() that takes array1
and array2 as parameters and calculates and returns the
combined sum of both of their contents i.e. it adds together all
the values in array1 and array2 and returns the sum to the
caller.
[5 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 6 of 7
APPROVED
Question 6 continued
b) The code above uses arrays to store groups of data. Name another
possible data structure from the Collections Framework which could be
used instead, and comment on any advantages or disadvantages of
using this.
[5 marks]
___________________________________________________________________
Object Oriented Software Development
COMP1307
Page 7 of 7