0% found this document useful (0 votes)
53 views4 pages

Sample Alternative Exam Coursework

This document contains sample exam questions for a Programming 2 course. It includes 4 questions testing knowledge of object-oriented programming concepts like classes, interfaces, inheritance and file I/O. It also includes 3 appendices that provide class definitions, class diagrams and code samples to reference in answering the questions. Students are asked to explain concepts, identify examples, write code samples, and discuss how to apply various Java features to the class models provided.

Uploaded by

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

Sample Alternative Exam Coursework

This document contains sample exam questions for a Programming 2 course. It includes 4 questions testing knowledge of object-oriented programming concepts like classes, interfaces, inheritance and file I/O. It also includes 3 appendices that provide class definitions, class diagrams and code samples to reference in answering the questions. Students are asked to explain concepts, identify examples, write code samples, and discuss how to apply various Java features to the class models provided.

Uploaded by

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

Programming 2 Sample Alternative Exam Coursework

Attempt all questions.

Q.1 (a) With reference to the outline class definition in Appendix A explain
the purpose and identify an example of:

(i) public [2]


(ii) final [2]
(iii) static [2]

(b) With reference to the model class diagram in Appendix B explain the
meaning of each of the following symbols and how they are specified
in Java:

(i) - [2]
(ii) # [2]

(c) With reference to the model class diagram in Appendix B identify the
type of the association between the Cricketer & Bowler classes and
explain how Java would implement it. [2]

Code a sample constructor for the Bowler class. [3]

Q.2 (a) With reference to the model class diagram in Appendix B, write the
content of a sample text file using the data supplied in Appendix B,
justifying your format. [5]

(b) With reference to the model class diagram in Appendix B explain the
required amendments to the model classes with respect to file
persistence:

(i) using a text file; [2]


(ii) using an object file. [2]

(c) Explain the operation of the load() method detailed in Appendix C


with reference to the class diagram in Appendix B and the list variable
defined below.

List<Cricketer> cricketerList; [6]


Q.3 (a) Select two implementations of the Java Collections Framework Set
interface explaining why you might choose to use each of your
selected implementations. [4]

(b) Describe how and explain why the Cricketer class illustrated in
Appendix A and B might:

(i) implement the Comparable interface [3]


(ii) define a Comparator object [3]

Q.4 (a) Explain the concept of modular design with respect to the principles of
Coupling and Cohesion. [5]

(b) Explain the purpose of Javadoc and NetBeans support for it. [5]
Appendix A
Outline Class Definition

public class Cricketer {


private final int id;
private String cricketerName;
private int totalRuns;
private float battingAverage;

private static int lastAllocatedId = 0;

public Cricketer() {
this.id = ++lastAllocatedId;
this.cricketerName = "TBC";
this.totalRuns = 0;
this.battingAverage = 0.0f;
}

public Cricketer(String cricketerName, int totalRuns,


float battingAverage) {
this.id = ++lastAllocatedId;
this.cricketerName = cricketerName;
this.totalRuns = totalRuns;
this.battingAverage = battingAverage;
}

Appendix B
Class Diagram

Sample Data

Id Cricketer Name Total Runs Batting Average Total Wickets Bowling Average
1 Mike Denness 1667 39.69 N/A N/A
2 Douglas Jardine 1296 48.00 N/A N/A
3 Ian Peebles 98 10.88 45 30.91
Appendix C
public void load(String filename) {
try{
FileInputStream fin = new FileInputStream(filename);
try (ObjectInputStream ois = new ObjectInputStream(fin)) {
cricketerList = (ArrayList<Cricketer>) ois.readObject();
}
}catch(IOException | ClassNotFoundException ex){
System.out.println(ex);
System.exit(0);
}
}

END OF APPENDICES

You might also like