SlideShare a Scribd company logo
1 of 5
Download to read offline
COMP1008 
Object-Oriented Programming 
2005 Exam 
2.5 Hours 
Examiner: 
Graham Roberts 
Department of Computer Science 
x33711, room 6.17 
G.Roberts@cs.ucl.ac.uk 
COMP1008
Answer ALL of Part I and TWO questions from Part II 
(Note that in all questions the Java code given in your answers does not have to be 
syntactically perfect but should, at least, be a good approximation.) 
Part I 
Q1. Consider this UML class diagram showing part of a program to manage the 
membership information for a professional society: 
Society 
-name : String 
+void addMember(String name,String address) 
+void addSeniorMember(String name,String address,int fee) 
+void addCtteeMember(SeniorMember member) 
+int getFeeTotal() 
ManagementCttee 
+void addCtteeMember(SeniorMember s) 
+void removeCtteeMember(String name) 
-name : String 
-address: String 
-int : fee 
a) Write a Java version of class ManagementCttee assuming it has this constructor: 
public ManagementCttee() 
[7 marks] 
b) Class Member is an abstract class. Explain the role of an abstract class. 
[2 marks] 
c) Write a Java version of class Member assuming it has this constructor: 
public Member(String name, String address) 
and that the method getFee() is abstract. 
[6 marks] 
d) Write a Java version of class StandardMember assuming it has this constructor: 
public StandardMember(String name, String address) 
and the standard membership fee is fixed at £50. 
[4 marks] 
(Question 1 cont. over page) 
TURN OVER 
COMP1008 
1 
Member 
+String getName() 
+String getAddress() 
+int getFee() 
1 0..* 
StandardMember 
+int getFee() 
SeniorMember 
+int getFee() 
1 
1 
1 0..*
(Question 1 cont.) 
e) Write a Java version of class SeniorMember assuming it has this constructor: 
public SeniorMember(String name, String address, int fee) 
where the membership fee is set when a SeniorMember object is created. 
[5 marks] 
f) Write a Java version of class Society assuming it has this constructor: 
public Society(String societyName) 
[8 marks] 
g) It should be possible to store the membership information in a data file. Assuming the 
use of a simple text-based data file: 
i) Describe the format of the data file. 
ii) Outline each method that needs to be added to each class to write the data file in 
the correct format. (Java code is not required). 
[8 marks] 
[Total 40 marks] 
End of Part I 
CONTINUED 
COMP1008 
2
Part II Answer TWO Questions from this Part 
Q2. a) Briefly explain each of the following Java terms: 
static method, dynamic binding, cast expression, protected, overriding, this 
[2 marks each, total of 12] 
b) List the keywords associated with exceptions in Java, giving a one sentence description 
of what each one is for. 
[5 marks] 
c) Write a class Stack in Java. The methods should throw exceptions where appropriate. 
[8 marks] 
d) Use examples to show how client code should use your Stack class from part c) and 
deal with any exceptions that might occur. 
[5 marks] 
[Total 30 marks] 
Q3. Consider a Linked List class. 
a) Write in Java a class ListElement to represent the elements in a linked list. 
[6 marks] 
b) Explain the idea of an iterator for a data structure like an ArrayList or LinkedList. 
[4 marks] 
c) Write a basic class LinkedList in Java using your element class from part a). The 
class should have public methods to add an element to the front of a list, add an element 
to the end of the list, and to return an iterator. An iterator implementation should be 
provided as a nested class. 
[12 marks] 
d) Write a method to show how an iterator from part c) can be used to print all the items in 
a list. 
[5 marks] 
e) A linked list has O(n) performance when accessing a given element in the list using an 
iterator. Explain what this means and where it is appropriate to use a list rather than 
another structure. 
[3 marks] 
[Total 30 marks] 
TURN OVER 
COMP1008 
3
Q4. 
a) The following are examples of good programming practice: 
i. Do not use public instance variables. 
ii. Use appropriate class, method and variable names. 
iii. Properly format source code. 
iv. Always initialise instance variables in a constructor. 
v. A method should be cohesive. 
For each example, explain why. 
[2 marks each, total of 10 marks] 
b) In Java, method parameters are passed by value — explain what this means and give 
examples of the consequences. 
[4 marks] 
c) Describe the role of the final keyword and give a list of guidelines for when it should 
and when it should not be used. 
[6 marks] 
d) Describe how a class can be tested. Illustrate your answer using class SeniorMember 
from Q1, showing how each method is tested. 
[10 marks] 
[Total 30 marks] 
End of Part II 
END OF PAPER 
COMP1008 
4

More Related Content

What's hot

GSP 125 Final Exam Guide
GSP 125 Final Exam GuideGSP 125 Final Exam Guide
GSP 125 Final Exam Guidemonsterr20
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7ashhadiqbal
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Abdul Hannan
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7helpido6
 
GSP 125 Education Specialist / snaptutorial.com
  GSP 125 Education Specialist / snaptutorial.com  GSP 125 Education Specialist / snaptutorial.com
GSP 125 Education Specialist / snaptutorial.comstevesonz146
 
GSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.comGSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.comdonaldzs162
 
Gsp 125 Education Organization -- snaptutorial.com
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.comDavisMurphyB85
 
Gsp 125 Future Our Mission/newtonhelp.com
Gsp 125 Future Our Mission/newtonhelp.comGsp 125 Future Our Mission/newtonhelp.com
Gsp 125 Future Our Mission/newtonhelp.comamaranthbeg8
 

What's hot (20)

GSP 125 Final Exam Guide
GSP 125 Final Exam GuideGSP 125 Final Exam Guide
GSP 125 Final Exam Guide
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
Intake 38_1
Intake 38_1Intake 38_1
Intake 38_1
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
Thai
ThaiThai
Thai
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
Inheritance
InheritanceInheritance
Inheritance
 
Intake 37 1
Intake 37 1Intake 37 1
Intake 37 1
 
C# p8
C# p8C# p8
C# p8
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
User Defined Functions in C Language
User Defined Functions   in  C LanguageUser Defined Functions   in  C Language
User Defined Functions in C Language
 
GSP 125 Education Specialist / snaptutorial.com
  GSP 125 Education Specialist / snaptutorial.com  GSP 125 Education Specialist / snaptutorial.com
GSP 125 Education Specialist / snaptutorial.com
 
GSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.comGSP 125 Exceptional Education - snaptutorial.com
GSP 125 Exceptional Education - snaptutorial.com
 
Gsp 125 Education Organization -- snaptutorial.com
Gsp 125   Education Organization -- snaptutorial.comGsp 125   Education Organization -- snaptutorial.com
Gsp 125 Education Organization -- snaptutorial.com
 
Gsp 125 Future Our Mission/newtonhelp.com
Gsp 125 Future Our Mission/newtonhelp.comGsp 125 Future Our Mission/newtonhelp.com
Gsp 125 Future Our Mission/newtonhelp.com
 

Similar to E1

Oop r&s may 2019 (2)
Oop r&s may 2019 (2)Oop r&s may 2019 (2)
Oop r&s may 2019 (2)ktuonlinenotes
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programmingsoni_nits
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEWshyamuopten
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019ktuonlinenotes
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
Computer science ms
Computer science msComputer science ms
Computer science msB Bhuvanesh
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqpB Bhuvanesh
 
Model questions-b.sc .csit-6th-sem
Model questions-b.sc .csit-6th-semModel questions-b.sc .csit-6th-sem
Model questions-b.sc .csit-6th-semNayanBakhadyo
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
EN3085 Assessed Coursework 1 1. Create a class Complex .docx
EN3085 Assessed Coursework 1  1. Create a class Complex .docxEN3085 Assessed Coursework 1  1. Create a class Complex .docx
EN3085 Assessed Coursework 1 1. Create a class Complex .docxgidmanmary
 

Similar to E1 (20)

Oop r&s may 2019 (2)
Oop r&s may 2019 (2)Oop r&s may 2019 (2)
Oop r&s may 2019 (2)
 
Oop r&s may 2019
Oop r&s may 2019Oop r&s may 2019
Oop r&s may 2019
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programming
 
Oop sample ktu
Oop sample ktuOop sample ktu
Oop sample ktu
 
Paper
PaperPaper
Paper
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
Oop december 2018
Oop december 2018Oop december 2018
Oop december 2018
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019
 
Pcd201516
Pcd201516Pcd201516
Pcd201516
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
7th Semester (June; July-2015) Computer Science and Information Science Engin...
7th Semester (June; July-2015) Computer Science and Information Science Engin...7th Semester (June; July-2015) Computer Science and Information Science Engin...
7th Semester (June; July-2015) Computer Science and Information Science Engin...
 
Computer science ms
Computer science msComputer science ms
Computer science ms
 
2013-June: 5th Semester CSE / ISE Question Papers
2013-June: 5th  Semester CSE / ISE Question Papers2013-June: 5th  Semester CSE / ISE Question Papers
2013-June: 5th Semester CSE / ISE Question Papers
 
5th Semester CS / IS (2013-June) Question Papers
5th Semester CS / IS (2013-June) Question Papers5th Semester CS / IS (2013-June) Question Papers
5th Semester CS / IS (2013-June) Question Papers
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqp
 
Model questions-b.sc .csit-6th-sem
Model questions-b.sc .csit-6th-semModel questions-b.sc .csit-6th-sem
Model questions-b.sc .csit-6th-sem
 
C++ Unit_01
C++ Unit_01C++ Unit_01
C++ Unit_01
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
EN3085 Assessed Coursework 1 1. Create a class Complex .docx
EN3085 Assessed Coursework 1  1. Create a class Complex .docxEN3085 Assessed Coursework 1  1. Create a class Complex .docx
EN3085 Assessed Coursework 1 1. Create a class Complex .docx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 

More from lksoo

More from lksoo (20)

Lo48
Lo48Lo48
Lo48
 
Lo43
Lo43Lo43
Lo43
 
Lo39
Lo39Lo39
Lo39
 
Lo37
Lo37Lo37
Lo37
 
Lo27
Lo27Lo27
Lo27
 
Lo17
Lo17Lo17
Lo17
 
Lo12
Lo12Lo12
Lo12
 
T3
T3T3
T3
 
T2
T2T2
T2
 
T1
T1T1
T1
 
T4
T4T4
T4
 
P5
P5P5
P5
 
P4
P4P4
P4
 
P3
P3P3
P3
 
P1
P1P1
P1
 
P2
P2P2
P2
 
L10
L10L10
L10
 
L9
L9L9
L9
 
L8
L8L8
L8
 
L7
L7L7
L7
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

E1

  • 1. COMP1008 Object-Oriented Programming 2005 Exam 2.5 Hours Examiner: Graham Roberts Department of Computer Science x33711, room 6.17 G.Roberts@cs.ucl.ac.uk COMP1008
  • 2. Answer ALL of Part I and TWO questions from Part II (Note that in all questions the Java code given in your answers does not have to be syntactically perfect but should, at least, be a good approximation.) Part I Q1. Consider this UML class diagram showing part of a program to manage the membership information for a professional society: Society -name : String +void addMember(String name,String address) +void addSeniorMember(String name,String address,int fee) +void addCtteeMember(SeniorMember member) +int getFeeTotal() ManagementCttee +void addCtteeMember(SeniorMember s) +void removeCtteeMember(String name) -name : String -address: String -int : fee a) Write a Java version of class ManagementCttee assuming it has this constructor: public ManagementCttee() [7 marks] b) Class Member is an abstract class. Explain the role of an abstract class. [2 marks] c) Write a Java version of class Member assuming it has this constructor: public Member(String name, String address) and that the method getFee() is abstract. [6 marks] d) Write a Java version of class StandardMember assuming it has this constructor: public StandardMember(String name, String address) and the standard membership fee is fixed at £50. [4 marks] (Question 1 cont. over page) TURN OVER COMP1008 1 Member +String getName() +String getAddress() +int getFee() 1 0..* StandardMember +int getFee() SeniorMember +int getFee() 1 1 1 0..*
  • 3. (Question 1 cont.) e) Write a Java version of class SeniorMember assuming it has this constructor: public SeniorMember(String name, String address, int fee) where the membership fee is set when a SeniorMember object is created. [5 marks] f) Write a Java version of class Society assuming it has this constructor: public Society(String societyName) [8 marks] g) It should be possible to store the membership information in a data file. Assuming the use of a simple text-based data file: i) Describe the format of the data file. ii) Outline each method that needs to be added to each class to write the data file in the correct format. (Java code is not required). [8 marks] [Total 40 marks] End of Part I CONTINUED COMP1008 2
  • 4. Part II Answer TWO Questions from this Part Q2. a) Briefly explain each of the following Java terms: static method, dynamic binding, cast expression, protected, overriding, this [2 marks each, total of 12] b) List the keywords associated with exceptions in Java, giving a one sentence description of what each one is for. [5 marks] c) Write a class Stack in Java. The methods should throw exceptions where appropriate. [8 marks] d) Use examples to show how client code should use your Stack class from part c) and deal with any exceptions that might occur. [5 marks] [Total 30 marks] Q3. Consider a Linked List class. a) Write in Java a class ListElement to represent the elements in a linked list. [6 marks] b) Explain the idea of an iterator for a data structure like an ArrayList or LinkedList. [4 marks] c) Write a basic class LinkedList in Java using your element class from part a). The class should have public methods to add an element to the front of a list, add an element to the end of the list, and to return an iterator. An iterator implementation should be provided as a nested class. [12 marks] d) Write a method to show how an iterator from part c) can be used to print all the items in a list. [5 marks] e) A linked list has O(n) performance when accessing a given element in the list using an iterator. Explain what this means and where it is appropriate to use a list rather than another structure. [3 marks] [Total 30 marks] TURN OVER COMP1008 3
  • 5. Q4. a) The following are examples of good programming practice: i. Do not use public instance variables. ii. Use appropriate class, method and variable names. iii. Properly format source code. iv. Always initialise instance variables in a constructor. v. A method should be cohesive. For each example, explain why. [2 marks each, total of 10 marks] b) In Java, method parameters are passed by value — explain what this means and give examples of the consequences. [4 marks] c) Describe the role of the final keyword and give a list of guidelines for when it should and when it should not be used. [6 marks] d) Describe how a class can be tested. Illustrate your answer using class SeniorMember from Q1, showing how each method is tested. [10 marks] [Total 30 marks] End of Part II END OF PAPER COMP1008 4