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

Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 

Recently uploaded (20)

Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 

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