Skip to main content

COMP2511 26T2 Sample Exam - Set B

Unofficial practice paper - 100 marks

Important Instructions
  • Answer all questions.
  • For Questions 14 and 15, your Java code must compile.
  • Starter project: sample-exam-set-b/.
  • Run ./gradlew compile from the starter-project directory to check compilation.
  • Baseline regression tests for Question 15 should pass before and after your refactor. Some task tests are intentionally failing in the untouched starter code because they test functionality you are asked to implement.
  • Unless a question says otherwise, justify design choices using terminology from COMP2511 lectures.

Section 1: Multiple Choice (8 marks)

Write your answers in mcq.txt or submit using the command below.

Question 1 (1 mark)

A university music platform stores playlists. A song can exist in the music catalogue even if every playlist that references it is deleted.

The relationship between a playlist and its songs is best modelled as:

  • A) Composition
  • B) Aggregation
  • C) Inheritance
  • D) Neither aggregation nor composition

Run this command in your terminal to submit

2511 submit 1


Question 2 (1 mark)

Consider the following method:

static void printAnimals(List<? extends Animal> animals) {
for (Animal animal : animals) {
System.out.println(animal);
}
}

Which statement is correct?

  • A) The method can accept List<Animal> but not List<Dog>.
  • B) The method can accept both List<Animal> and List<Dog> if Dog extends Animal.
  • C) The wildcard means the list may contain only exact instances of Animal.
  • D) ? extends Animal allows the method to safely add arbitrary Animal objects to the list.

Run this command in your terminal to submit

2511 submit 2


Question 3 (1 mark)

Which statement about Java exceptions is most accurate?

  • A) Every subclass of RuntimeException is checked by the compiler.
  • B) A checked exception must generally be caught or declared.
  • C) Error should normally be caught and converted into a business exception.
  • D) finally executes only when no exception is thrown.

Run this command in your terminal to submit

2511 submit 3


Question 4 (1 mark)

You need a lambda that receives an Order and returns true when that order requires manual review.

Which functional interface is the most semantically appropriate?

  • A) Consumer<Order>
  • B) Supplier<Order>
  • C) Predicate<Order>
  • D) Function<Order, Void>

Run this command in your terminal to submit

2511 submit 4


Question 5 (1 mark)

A high-level CheckoutService directly constructs StripePaymentClient, PostgresOrderRepository, and TwilioSmsClient. Replacing any one infrastructure technology requires modifying CheckoutService.

Which SOLID principle is most directly being violated?

  • A) Single Responsibility Principle
  • B) Open-Closed Principle
  • C) Interface Segregation Principle
  • D) Dependency Inversion Principle

Run this command in your terminal to submit

2511 submit 5


Question 6 (1 mark)

A weather station should notify an arbitrary number of displays whenever its measurements change. Displays may be added or removed while the program is running.

Which pattern is most suitable?

  • A) Builder
  • B) Observer
  • C) Singleton
  • D) Composite

Run this command in your terminal to submit

2511 submit 6


Question 7 (1 mark)

A photo-sharing application needs to generate thumbnails whenever a user uploads an image. Uploads are irregular, the thumbnail operation is short-lived and stateless, and the team does not want to manage servers for the thumbnail workers.

Which architectural style is the most natural fit?

  • A) Layered Monolith
  • B) Modular Monolith
  • C) Serverless
  • D) Microservices only, because serverless cannot react to events

Run this command in your terminal to submit

2511 submit 7


Question 8 (1 mark)

Which is a common trade-off of a microservice architecture?

  • A) It removes network failures because all calls are in-process.
  • B) It can increase operational, deployment, tracing, and distributed-data complexity.
  • C) It requires every service to use the same programming language and database.
  • D) It prevents independent scaling of different parts of the system.

Run this command in your terminal to submit

2511 submit 8


Check your answers

Check your submitted answers before moving on to the next section.

List all your submitted answers
2511 check
List submitted answer for single question
2511 check <question_number>

Section 2: Short Answer (22 marks)

Question 9 (4 marks)

Consider the following code:

public class Account {
/**
* @precondition amount > 0
* @postcondition balance decreases by exactly amount
*/
public void withdraw(double amount) {
// ...
}
}

public class PremiumAccount extends Account {
/**
* @precondition amount >= 100
* @postcondition balance decreases by at least amount
*/
@Override
public void withdraw(double amount) {
// ...
}
}

Is PremiumAccount a valid behavioural subtype of Account under Design by Contract and the Liskov Substitution Principle?

Explain your answer with explicit reference to the rules for overriding preconditions and postconditions.

Write your answer inside q09.txt.

Run this command in your terminal to submit

2511 submit 9


Question 10 (4 marks)

Suppose:

class Animal {}
class Dog extends Animal {}

List<Dog> dogs = new ArrayList<>();

A student tries to call:

void inspect(List<Animal> animals) { ... }

inspect(dogs);
  1. Explain why this does not compile even though Dog is a subtype of Animal. (2 marks)
  2. Give a suitable revised parameter type for inspect if the method only needs to read values as Animal, and briefly justify it. (2 marks)

Write your answer inside q10.txt.

Run this command in your terminal to submit

2511 submit 10


Question 11 (5 marks)

Consider the following method in ReportExporter:

public class ReportExporter {
public String export(Report report, String format) {
if (format.equals("CSV")) {
String header = report.getTitle() + "," + report.getAuthor();
String body = buildCsvRows(report.getRows());
audit("CSV", report.getTitle());
return header + "\n" + body;
} else if (format.equals("JSON")) {
String header = report.getTitle() + " - " + report.getAuthor();
String body = buildJsonRows(report.getRows());
audit("JSON", report.getTitle());
return "{\"meta\":\"" + header + "\",\"rows\":" + body + "}";
} else if (format.equals("XML")) {
String header = report.getTitle() + " - " + report.getAuthor();
String body = buildXmlRows(report.getRows());
audit("XML", report.getTitle());
return "<report><meta>" + header + "</meta>" + body + "</report>";
}
throw new IllegalArgumentException("Unknown format");
}
}

Identify two significant code/design smells in this method. For each smell:

  • Explain why it is a problem, and
  • Describe a refactoring that would address the underlying design issue.

You do not need to write the full refactored code.

Write your answer inside q11.txt.

Run this command in your terminal to submit

2511 submit 11


Question 12 (4 marks)

An online checkout has a base delivery service. At runtime, a customer may independently add any combination of:

  • signature on delivery,
  • shipping insurance,
  • refrigerated handling, and
  • gift packaging.

Each option adds behaviour and cost to the same delivery object. New options are expected in future, and the developers want to avoid creating subclasses for every possible combination.

Choose the most appropriate design pattern and justify your choice by mapping the scenario to the pattern's key roles and intent.

Write your answer inside q12.txt.

Run this command in your terminal to submit

2511 submit 12


Question 13 (5 marks)

A learning platform stores course content in a hierarchy. A course contains modules; modules may contain lessons or other nested modules; lessons are leaves. The system must perform operations such as:

  • calculate the total estimated study time of any item,
  • display a whole subtree, and
  • treat a lesson and a module uniformly when traversing course content.

Choose the most appropriate design pattern. Explain the mapping of this domain to the pattern, including the roles played by the common abstraction, leaf objects, and composite objects.

Write your answer inside q13.txt.

Run this command in your terminal to submit

2511 submit 13


Check your answers

Check your submitted answers before moving on to the next section.

List all your submitted answers
2511 check

Section 3: Design & Programming (40 marks)

Your code for every part of this section needs to compile. This includes Question 14. If your code fails to compile, you may not get any automarking marks.

To check whether your code compiles, run ./gradlew compile. You should see BUILD SUCCESSFUL.

VS Code Workspace

You need to be inside the sample-exam-set-b folder for VS Code to configure itself properly.

code ~/sample-exam-set-b

Question 14 (12 marks)

CSE is building a booking system for university makerspaces.

The system has the following requirements:

  • The university operates multiple makerspaces.
  • Each makerspace contains one or more rooms.
  • Each room contains zero or more workstations. A workstation belongs to exactly one room and does not meaningfully exist independently of that room in this system.
  • Each makerspace has exactly one coordinator, who is a staff member.
  • Each room has exactly one supervisor, who is also a staff member. Staff members exist independently of makerspaces and rooms and may be reassigned.
  • Students exist independently of makerspaces.
  • A student can reserve a workstation for a start and end time. A reservation refers to exactly one student and exactly one workstation.
  • A student may have many reservations over time. A workstation may also have many reservations over time, provided they do not overlap.
  • A makerspace owns a collection of movable equipment items. Equipment can be moved between rooms without being recreated.
  • Students can check out and return equipment.

Model the domain for the above requirements to form the basis of a software solution.

Your answer should include:

  • Interfaces where appropriate
  • Class signatures and inheritance relationships where appropriate
  • Key fields
  • Method signatures
  • Aggregation/composition relationships and cardinalities, written as comments or JavaDoc.

You do not need to implement any of these classes/methods, you are simply providing the prototypes / stubs. Any design decisions that you feel need justifying you can do so as a comment / JavaDoc in the respective Java file.

Do not draw a UML diagram for this question.

An interface for the entire system has been provided to you in app/src/main/java/q14/MakerspaceController.java. You can modify these method prototypes if you like, though you shouldn't need to.

There is a lot of undefined behaviour about this system, which is intentional. You can make as many assumptions as you need, so long as they don't reduce the scope of the specification.

You will be assessed on:

  • Entity modelling and responsibilities (4 marks)
  • Relationships, ownership and cardinalities (4 marks)
  • Modelling of system functionality and API quality (4 marks)

Run this command in your terminal to submit

2511 submit 14


Question 15 (28 marks)

Regression Tests

You do not need any knowledge of frontend coding to complete this exercise. The regression tests in ParcelSystemTest.java must pass.

The starter code in app/src/main/java/q15/ implements a small parcel-delivery system.

The public facade is ParcelController. Regression/task tests are in: app/src/test/java/q15/ParcelSystemTest.java

a) Pricing Policies (10 marks)

The current PricingCalculator contains a growing conditional chain for delivery modes.

Existing modes must preserve the following behaviour:

  • STANDARD: 5 + 1.25 * weightKg
  • EXPRESS: 10 + 2.0 * weightKg, plus a $5 surcharge when distanceKm > 20
  • SAME_DAY: 20 + 3.0 * weightKg + 0.5 * distanceKm

A new mode must now be added:

  • GREEN: 4 + 1.0 * weightKg + 0.2 * distanceKm

The product team expects additional pricing policies in future. A caller must be able to choose a delivery mode at runtime, while the pricing implementation should be open to extension without continuing to modify one large conditional method.

Tasks:

  • i) In q15.txt, briefly identify the design problem and name the most suitable design pattern. (2 marks)
  • ii) Refactor the pricing design using that pattern, preserving existing behaviour and adding GREEN. (8 marks)

The public call below must continue to work:

controller.quote(parcelId, mode);

b) Status Notifications (10 marks)

The starter Parcel class is tightly coupled to exactly two notification mechanisms: email and SMS.

New requirements:

  • Arbitrary listeners must be able to subscribe to a particular parcel at runtime.
  • Listeners receive the parcel id, old status and new status whenever the parcel status changes.
  • A listener may unsubscribe and must then receive no further updates.
  • Existing email and SMS behaviour must continue to work after your refactor.
  • Future notification channels should be addable without changing the core parcel status-update logic.

The provided controller methods are:

void subscribe(String parcelId, StatusListener listener)
void unsubscribe(String parcelId, StatusListener listener)

Tasks:

  • i) In q15.txt, name and justify the most suitable design pattern. (2 marks)
  • ii) Refactor the implementation so that the requirements and tests are satisfied. (8 marks)

c) Open Refactoring (8 marks)

Other than the pricing conditional and the fixed notification-channel dependency addressed in Parts A and B, the starter code contains further code/design smells.

Look through the code in all files in the q15 package.

Identify and refactor approximately two moderate or severe smells in separate areas of the codebase.

For each smell, record in q15.txt:

  • where it occurs,
  • why it is a design/code-quality problem, and
  • what refactoring you performed.

The regression behaviour in ParcelSystemTest must remain passing.

Run this command in your terminal to submit

2511 submit 15


Check your answers

Check your submitted answers before moving on to the next section.

List all your submitted answers
2511 check

Section 4: Software Architecture (30 marks)

Question 16 (8 marks)

A university enrolment platform currently stores enrolments in one relational database. The team is considering moving the course-search catalogue to a separate document database because catalogue records have irregular metadata and are read much more frequently than they are updated.

However:

  • Enrolment transactions must remain strongly consistent,
  • The team has limited operational capacity,
  • Search response time is important during enrolment periods, and
  • Introducing another database technology increases operational complexity.

Answer both parts:

  1. Identify two architectural characteristics that are especially important to this decision and explain why. (3 marks)
  2. Write a concise ADR for the decision to either adopt or reject a separate document database for the catalogue. Include at least: Title, Status, Context, Decision, and Consequences. Your decision may be either choice if it is well justified. (5 marks)

Write your answer inside q16.txt.

Run this command in your terminal to submit

2511 submit 16


Question 17 (10 marks)

A six-person startup is building a business-management product with the following characteristics:

  • It has clear business domains: accounts, invoicing, inventory, reporting and notifications.
  • The team wants strong boundaries between these domains so features can evolve without creating a tangled codebase.
  • Most operations are ordinary request/response business transactions.
  • The expected load for the next two years is moderate and can be handled by scaling one application deployment.
  • Cross-domain transactions are common and should remain straightforward.
  • The company wants low deployment and operational complexity because there is no dedicated platform team.
  • In future, one or two modules might need to be extracted into independently deployed services, but there is no current need for independent scaling.

Choose the most suitable architecture from the styles covered in COMP2511 lectures. Justify your choice using functional and non-functional requirements and architectural characteristics.

Your answer should also explain why at least two plausible alternatives are less suitable at this stage.

Write your answer inside q17.txt.

Run this command in your terminal to submit

2511 submit 17


Question 18 (12 marks)

Sequence Diagrams

You must write the sequence diagram using mermaid syntax. You can use the mermaid syntax docs to help you.

View mermaid render

See the exam environment explanation for more information on how to render and preview your mermaid diagram in VS Code.

An online assignment-submission system behaves as follows:

  1. A student uploads a submission through the Submission Portal.
  2. The portal sends the submission request to Submission Service.
  3. Submission Service asks Auth Service to validate the student's token.
  4. If authentication fails, the system returns an authentication error to the student and performs no storage operations.
  5. If authentication succeeds, Submission Service asks Course Service whether the submission deadline is still open.
  6. If the deadline is closed, the system returns a deadline-closed error and performs no storage operations.
  7. If the deadline is open:
    • Submission Service stores the submitted file in File Store;
    • It records submission metadata in Submission Database;
    • It sends a success response containing the submission id back to the portal;
    • The portal confirms the submission id to the student.
  8. After a successful submission, Submission Service publishes a SubmissionCreated event to an Event Bus.
  9. Receipt Service consumes that event and asks Email Service to send a receipt email to the student.

Draw a sequence diagram using mermaid syntax that clearly represents:

  • The actor and major participants,
  • The ordering of calls and responses,
  • The authentication and deadline conditional branches (alt / else),
  • The successful storage flow, and
  • The post-submission receipt flow.

Write your answer inside q18.md.

Run this command in your terminal to submit

2511 submit 18


End of Exam