Programming 2 Sample Questions
Programming 2 Sample Questions
Q1
(a) With reference to the model class diagram in Appendix A and the partial
class definitions in Appendix B, write down and complete the missing
numbered phrases explaining the purpose of each. Note some phrases are
used more than once in the code. [14]
(b) With reference to the partial class definitions in Appendix B and your answer
to (a), explain each of the components of the method definitions. [6]
(c) With reference to the model class diagram in Appendix C explain the
different types of methods required giving an example of each type using a
method signature. [16]
(i) public;
(ii) private;
(iii) static;
(iv) final; [4]
Q2
(a) With reference to the model class diagram in Appendix A and the text file
sample in Appendix D explain the operation of the load() method in
Appendix E used to populate a Repository object from the sample text file. [10]
(b) With reference to your answer to (a) explain the changes required to load
from an object file and any required changes to model class definitions. [5]
(c) Explain issues concerning the store() method detailed in Appendix F with
reference to the model class diagram in Appendix A and partial class
definitions in Appendix B. [5]
(d) With reference to the model class diagram in Appendix C and the partial
method definition in Appendix G, complete and write down the missing
numbered phrases explaining the purpose of each. [14]
(e) With reference to the model class diagram in Appendix C and the partial
method definition in Appendix G, produce a sample text file format to persist
Artist & Painting objects. [6]
Q3
(a) Explain the purpose, benefits and organisation of the Java Collections
Framework. [12]
(b) With reference to the class diagram in Appendix A and partial class
definitions in Appendix B, explain any changes to the classes to implement
the following functionality using the list variable defined below.
List<Attendee> attendeeList;
(i) List;
(ii) Set. [8]
(d) With reference to the class diagram in Appendix C, explain any changes to
the class to implement the following functionality using the list variable
defined below.
List<Artist> artists;
(i) a report showing all artist details in order of artist name;
(ii) a report showing all artist details in order of number of
paintings. [8]
(e) With reference to your answer to (d), explain any changes required if the
variable type is changed to:
(f) Explain the differences and use of an Iterator and a ListIterator. [2]
Q4
(a) With reference to the class diagram in Appendix H, explain the role of each
class. [10]
(b) With reference to the class diagram in Appendix H, for each statement
below explain why you think the statement is TRUE or FALSE.
(ii) documentation;
(iii) refactoring;
(g) Using an application scenario of your choice identify ways in which you
might use the NetBeans support below:
(b) documentation;
(c) refactoring;
Appendix B
Attendee
public class Attendee {
---1--- ---2--- int id;
---1--- String name;
---3--- int lastIdAllocated = 0;
public Attendee() {
this.id = ++lastIdAllocated;
this.name = "Unknown";
}
---4---
public String toString() {
return "Id: " + Integer.toString(this.id) +
" Name: " + this.name;
}
}
Volunteer
public class Volunteer ---5--- Attendee {
private String role;
public Volunteer() {
---6---;
this.role = "TBA";
}
---4---
public String toString() {
return super.toString() + " Role: " + this.role;
}
}
Appendix C
Appendix D
1,"Leo Messi"
2,"Andres Iniesta","Greeter"
3,"Sergi Busquets"
4,"Carles Puyol","TBA"
Appendix E
Appendix F
Appendix I
(b)
Answer should identify and explain the purpose of the components of a method definition
with reference to the code in Appendix B
Access modifier, method name, arguments, method body, void, return
- 1 mark per point
(c)
Answer should identify typical methods including constructors, getters, setters, toString,
equals, hashCode, collection methods, comparison methods
- 2 marks per method type identified with justification
(d)
1 mark per modifier
2
(a)
Filename supllied through parameter
Repository object created
Stream opened
Repetitively read lines until no more
Split line into temp String array using delimiter
Access first array location to retrieve id value and convert to Integer
Access second array location to retrieve name stripping off quotes
If more than 2 values in the temp array then
Access next location for role
Create Volunteer object and add to repository
Else
Create Attendee object and add to repository
EndIf
Close stream
Return Repository
1 mark each
(d)
1 – FileReader
2 – Integer.parseInt
3 – ArrayList or LinkedList
4 – new Artist(artistName, paintingsList)
5 – repository.add(artist)
6 - Line = br.readLine()
7 – return repository
Answer should explain the points above with reference to the reports requested
1 mark per valid point
(c)
1 mark each for type explanation
2 marks each for implementations e.g. ArrayList, HashSet etc.
1 mark each for algorithm examples
(d)
Implementation of hashCode() and equals() methods to allow comparison
Implement Comparable interface and compareTo() method
Create Comparator with compare() method
Answer should explain the points above with reference to the reports requested
1 mark per valid point
(e)
No essential difference to comparison implementation, however collection implementation
should be a TreeSet
- 1 mark per valid point
(f)
Explanation of difference, additional methods etc.
- 1 mark per valid point
4
(a)
Classes:
App, Controller, InputHelper, Repository & Interface, DAO Implementations & Interface,
Model Classes
The answer should explain the purpose of each type of class and interface describing their
role in the app's implementation
1 mark per valid point
(b)
(i) False (ii) False (iii) True
2 marks each including explanation
(c)
Answer should explain coupling and cohesion
1 mark per valid point – mark flexibly
(d)
3 marks per topic – mark flexibly
(e)
Class implements interface providing concrete methods for the load and store methods with
same method signatures. Additional methods can be added where necessary.
1 mark per valid point
(f)
Predicate, Supplier, Consumer, Function
2 mark per interface with explanation and use
(g)
Answer should reference chosen scenario
5 marks per topic – mark flexibly