COMP2511-java代写
时间:2022-11-23
Sample Exam
COMP2511 22T2 Final Exam
Please read the page for all information on the final exam.COMP2511 Exam Information Page
DO NOT answer all questions.
The exam consists of three sections:
Short Answer (25 marks)
Answer all of Q1 - Q6 core questions (19 marks)
Answer out of choice questions Q7 - Q12 (6 marks)two six
If you answer more than two out of the six choice questions we will only mark the first two.
Extended Answer (10 marks)
Answer Question 13 (10 marks)
Design & Programming (65 marks)
Question 14
Answer all of core parts a, b, c, d (26 marks)
Answer out of choice parts e or f (9 marks)one two
If you answer more than one choice part we will only mark the first one.
Question 15
Answer all of core parts a, b, c, d, e (30 marks)
This question does not have any choice parts.
Getting Setup
Your personalised exam repo can be found here:
REMEMBER to replace the zID below with your own.
https://gitlab.cse.unsw.edu.au/COMP2511/22T3/students/z5555555/exam-sample
To submit your work, push to the branch of your repository. All work must be pushed before the deadline.master
Section 1: Short Answer (25 marks)
Question One (4 marks)
In each of the following code snippets,
Identify the logic error present (1 mark); and
Write a failing assertion that would catch the logic error as part of a unit test (e.g. ) (1 mark)assertEquals(4, f(2))
Write your answers inside .q1.txt
Part A (2 marks)
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof Article)) return false;
Article other = (Article) obj;
return this.title.equals(other.title) && this.views.equals(other.
views);
}
1.
2.
3.
4.
5.
6.
Part B (2 marks)
public List withoutOddNumbers(List numbers) {
for (Integer number : numbers) {
if (number % 2 != 0) {
numbers.remove(number);
}
}
return new ArrayList(numbers);
}
Question Two (3 marks)
Part A (1 mark)
Select one or more of the following correct answers:
The dependency inversion principle encourages programming to ____________
An implementation, not an interface
An interface, not an implementation
Abstractions, not concretions
Concretions, not abstractions
A black box
A white box
Write your answer inside .q2.txt
Part B (2 marks)
Consider the class versus the class from the Blackout assignment, provided in and .Angle MathsHelper Angle.java MathsHelper.java
Which class do you think has better ? Justify your answer.cohesion
Write your answer inside .q2.txt
Question Three (4 marks)
In 22T3 COMP2511 is contemplating moving to Jira for students to manage their projects. There are three different types of Jira boards that can
be used: Scrum, Kanban and Bug Tracking. All boards have the same flow of work, and allow for features including support for issue tracking and
customisation of project-specific features. However, some elements may vary for each type of board - Scrum boards take two week sprints
whereas Kanban has a series of epics that are progressed through, and bug tracking projects only have a single backlog. Once a project is
created as Scrum, Kanban or Bug Tracking it cannot change its type.
What Design Pattern could be used to model this? In answering, justify your choice by describing how the above scenario relates to the key
of your chosen Design Pattern.characteristics
Write your answer inside .q3.txt
Question Four (2 marks)
Webster is waiting for tickets to be released to the next Sydney Swans game. He has setup notifications on his phone that will alert him when the
tickets open, and he is also checking his phone regularly since there are a limited number of tickets and he needs to be one of the first ones to
book to save a place.
Which implementation of the Observer Pattern is present in the above scenario, or ? Justify your answer.push pull
Write your answer inside .q4.txt
Question Five (3 marks)
Identify the code smells present in the following pieces of code, and explain whether you think this is indicative of an underlying design problem,
if so what the problem is, or alternatively if you think you don't have enough information to tell.
Write your answers inside .q5.txt
Part A (2 marks)
Scenario: A satellite simulation where various satellites are orbiting the Jovian ring.
private List standardSatellites;
private List quantumSatellites;
/**
** Run the simulation for a single minute
**/
public void simulate() {
// Update Position of Satellites
for (Satellite s : standardSatellites) {
s.setPosition(s.getPosition() + 3000 / s.getHeight());
}
for (Satellite s : quantumSatellites) {
s.setPosition(s.getPosition() + 2000 / s.getHeight());
}
// ... so on
}
Part B (1 mark)
public class ConsumeService {
// ...
public void startConsumeService(Config config, Consumer consumer,
Logger logger,
Tracer tracer, Metrics metrics,
String[] topics,
boolean willTimeout, int timeout) {
// ...
}
}
Question Six (3 marks)
During the project, a student on the forum asked the following question:
Are we allowed to modify the class given to us?Position
Tina answered the following:
Yes, so long as you don't break the preconditions and postconditions of that class - we will rely on these for automarking.
With reference to the Liskov Substitution Principle, explain what is meant by "breaking the preconditions and postconditions". Provide one
example (either breaking the preconditions or postconditions) of this with reference to the class, provided for you in and Position Position.java
explain how it would affect the automarking in this scenario.
Write your answer inside .q6.txt
You must answer two (2) out of the following six (6) choice questions.
Question Seven (3 marks)
Consider the following lambda function which checks if a number is prime. The type signature has been redacted.
[redacted] isPrime = n -> {
for (int i = 0; i < Math.sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
};
Which of the following answers could be correct? Out of these possible answers, explain which one is the most semantically correct.
a. Function
b. Function
c. Consumer
d. Consumer
e. Predicate
f. Predicate
g. Supplier
h. Supplier
Write your answer inside . Leave blank if you are not attempting this question.q7.txt q7.txt
Question Eight (3 marks)
During the project, Sienna and her group came up with the following testing plan:
To make sure our code is 100% correct, we will write unit tests for everything at the class level, and controller tests for
everything as well at the system level.
Here is an example of their test list for implementing battles:
Unit Tests Controller / System Tests
Test the player wins when battling a mercenary
Test the player loses when battling a mercenary
Test the player wins when battling a mercenary while invincible
Test the player wins when battling a zombie
Test the player loses when battling a zombie
Test the player wins when battling a zombie while invincible
Test the player wins when battling a spider
Test the player loses when battling a spider
Test the player wins when battling a spider while invincible
Test the player wins when battling a mercenary
Test the player loses when battling a mercenary
Test the player wins when battling a mercenary while invincible
Test the player wins when battling a zombie
Test the player loses when battling a zombie
Test the player wins when battling a zombie while invincible
Test the player wins when battling a spider
Test the player loses when battling a spider
Test the player wins when battling a spider while invincible
Explain why this is poor test design, and a possible alternative approach to testing.
Write your answer inside . Leave blank if you are not attempting this question.q8.txt q8.txt
1.
2.
Continue to Section 2 if you've answered two out of two choice questions already!
Question Nine (3 marks)
In a few days, Nick is going to run the automarker and download everyone's exam repositories. The script contains a simple loop which collect
downloads each student's repo, as follows. You can refer to the following pseudocode:
for student in students
print "==== Processing " + student + "===="
git clone path + "/" + student + "/exam.git" student
# more stuff
done
However, when multiple operations are run in close proximity by the same machine (usually around 10) Gitlab implements a git clone
protection strategy which blocks further s from being performed by that machine, in order to prevent someone launching a Denial of git clone
Service attack. When downloading repositories, however, this means that some operations fail. When the exam automarking is run, git clone
it is only run on the present folders and around 30 students won't receive their exam marks because of this error.
What was the flaw (or flaws) in this design? Explain two measures that could have been put in place to mitigate this from happening.
Write your answer inside . Leave blank if you are not attempting this question.q9.txt q9.txt
Question Ten (3 marks)
All software development is maintenance.
With reference to your project, in a paragraph or so, discuss the accuracy of the statement above.
Write your answer inside . Leave blank if you are not attempting this question.q10.txt q10.txt
Question Eleven (3 marks)
Liam is constructing a painting application, and has created a UML diagram which can be found in to model the domain.Q11-Quaint.pdf
Identify the Design Patterns used in Liam's implementation. (1 mark)
Pick of the design patterns and describe the how the implementation relates to the key characteristics of the design pattern. (2 marks)one
Write your answer inside . Leave blank if you are not attempting this question.q11.txt q11.txt
Question Twelve (3 marks)
In the asynchronous implementation of event-driven programming, Consumers and Producers communicate by reading from and writing to a
shared channel. Different types of events can flow through the channel, and Consumers and Producers can wear multiple hats - a Consumer can
also act as a Producer and vice-versa. In this case, when the entity consumes an event it immediately produces another event. Consumers
"subscribe" to events of a particular colour which are created by Producers.
Consider the following scenario where a Consumer C3, which consumes red events also acts as a Producer of red events.
Explain the problem caused by this design.
Write your answer inside . Leave blank if you are not attempting this question.q12.txt q12.txt
Now is a good time to push your work to GitLab.
Section 2: Extended Answer (10 marks)
Question Thirteen (10 marks)
Many online newspapers such as the provide a special type of article called a "live article", which uses the benefits of Sydney Morning Herald
real-time updating in the digital age to consistently provide new stories to readers throughout the day, each of these stories is called a (see post
below).
In this question, you will be designing, a system with the following functional requirements:but not implementing
A new live article can be created, storing the time it was first created;
A new can be made on the article, which includes the content, post title and a time the post was created;post
An existing post can have its content updated;
An existing post can be deleted
A comment can be made on a post
Model the domain for the above requirements to form the basis of a potential software solution. Your answer should include:
Interfaces, if applicable
Class Signatures, including inheritance relationships where appropriate
Method Signatures
Key Fields and relationships, including aggregations, compositions and cardinalities between entities (written as comments)
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 file.
An interface for the entire system has been provided to you in . You can modify these src/main/java/q13/LiveArticleSystem.java
method prototypes if you like, though you shouldn't need to.
There is a of undefined behaviour about this system, which is intentional. You can make as many assumptions as you need, so long as they lot
don't reduce the scope of the specification.
You will be assessed on:
Modelling of Entities (4 marks)
Aggregations, Compositions and Cardinalities (3 marks)
Modelling of Functionality (3 marks)
Try to spend around 10 minutes on this question to give yourself plenty of time for the Design & Programming section.
Now is a good time to push your work to GitLab.
Section 3: Design & Programming (65 marks)
Question Fourteen (35 marks)
In Lab 05: SSO, we looked at a system that handled . In this question, we will be dealing with in the context of a Authentication Authorisation
system that you have been working with - Gitlab.
In Gitlab, there are two types of "nodes" in a structural tree of permissions and access - and .groups projects
Groups are nodes that can contain projects, or other subgroups;
Projects are nodes that do not have any subgroups or subprojects, and act as a code repository (like this exam repo)
In the above example, the tree consists of the COMP2511 group which contains the 22T2 group, which contains STAFF group which contains
the tutor-notes project, other projects and another group called repos.
At each level, a user can have one of four different types of :permissions
Owner
Maintainer
Developer
1.
2.
3.
Reporter
For the purposes of this question, the only actions that will require permissions are:
Creating a project, which requires Developer permissions
Creating a subgroup, which requires Maintainer permissions
Changing the permissions of another member in the group, which requires Owner Permissions
Inside we have implemented a very basic system that addresses the above requirements. In this question you will be required src/q14/gitlab
to , , and .analyse the existing code make notes of design smells and refactor the code adapt the code to an evolution in the requirements
There are a series of regression tests that currently pass on the code in within .RegressionsTests GitlabTest.java
a) Code Analysis (5 marks)
Look at the code inside the package and in answer the following questions:gitlab q14.txt
Explain what Design Pattern is being used to represent the system, and how the domain relates to the key characteristics of the pattern. (2
marks)
Identify what you think is the main design problem present in the existing code, including what smells are indicating the problem. (2 marks)
Which of the following design smells is also present in the code? (1 mark)
Divergent Change
Inappropriate Intimacy
Refused Bequest
Message Chains
b) Refactoring a Method (3 marks)
Refactor the following method inside to use streams:GitlabGroup
public List getUsersOfPermissionLevel(PermissionsLevel level) {
Set membersSet = members.keySet();
List names = new ArrayList();
for (User member : membersSet) {
if (members.get(member).equals(level)) {
names.add(member.getName());
}
}
return names;
}
In your refactoring, you will need to keep the regression tests passing, which are provided in within .RegressionsTests GitlabTest.java
c) Refactoring the Design (9 marks)
Based on your notes on Design Smells from Part A, refactor the design of the system accordingly.
You can make any changes as you like, so long as you keep the regression tests passing, which are provided in within RegressionsTests Git
.labTest.java
Any notes you wish to make regarding your refactoring can go inside .q14.txt
The mark breakdown for this question is as follows:
Maintaining Correctness (1 mark)
Refactoring (8 marks)
d) Filtering Authorisation (9 marks)
Currently, there is a major flaw in our implementation - the system does not permissions from groups to all their subgroups and projects.filter
For example, if Claire is the owner of the COMP2511 group, then she is also the owner of the 22T2 group, the STAFF group and the tutor-notes
project and has the same Owner permissions on those groups as if she was a direct owner of those respective nodes.
Similarly, if a user tries to give permissions to another user on a group which, by filtering authorisation they have permissions on, a already Gitl
should be thrown.abAuthorisationException
In code, here is an illustration of the above description:
User user = new User("Claire");
User user2 = new User("Eddie");
// Create a group
GitlabPermissionsNode group = new GitlabGroup("COMP2511", user);
// Create a subgroup
GitlabPermissionsNode group2 = assertDoesNotThrow(() -> group.
createSubgroup("22T2", user));
// Give dev access to Eddie on the COMP2511 group
assertDoesNotThrow(() -> group.updateUserPermissions(user2,
PermissionsLevel.DEVELOPER, user));
// Check that Eddie also has dev access on the 22T2 group
assertEquals(PermissionsLevel.DEVELOPER, group2.getUserPermissions
(user2));
// Try to give Eddie reporter access on the 22T2 group, but he is
already a developer of COMP2511
// so an authorisation error is thrown
assertThrows(GitlabAuthorisationException.class,
() -> group2.updateUserPermissions(user2, PermissionsLevel.
REPORTER, user));
Implement the 'filtering' of authorisation. A basic test has been provided to you in within PartDFilteringAuthorisationTests GitlabTest.
. We will run further tests on this question to assess the correctness of your solution.java
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Any notes you wish to make regarding your design can go inside .q14.txt
You need to complete (1) out of the following (2) choice parts of this question.one two
e) Factory Pattern (9 marks)
Inside , implement the following method:GitlabFactory.java
public static GitlabPermissionsNode gitlabFromJson(String jsonString,
User user)
The method should take in a string of the following format:gitlabFromJson
{
"type": "group",
"name": "COMP2511",
"subgroups": [
{
"type": "group",
"name": "22T2",
"subgroups": [
{
"type": "project",
"name": "dungeonmania"
}
]
},
{
"type": "project",
"name": "blackout"
}
]
}
and produce a with the corresponding structure. You do not need to handle any processing of group/project GitlabPermissionsNode
members in this part of the question.
A basic test has been provided to you in within . We will run further tests on this question to assess PartEFactoryTests GitlabTest.java
the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q14.txt
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Continue to Question Fifteen if you have already completed Part E!
f) Singleton Pattern (9 marks)
All projects in Gitlab run their pipelines on a single machine, which is why the runner gets very slow around project and assignment deadlines.
Currently, the method inside , which takes in an runnable "process" creates a new instance of the runner and runPipeline GitlabProject
runs the job.
public void runPipeline(Runnable job) {
GitlabRunner runner = new GitlabRunner();
runner.run(job);
}
Refactor the code to use the so that only one instance of the exists and only one job is able to run at a time (i.Singleton Pattern GitlabRunner
e. only one call can be made at a time).run
A basic test has been provided to you in within . We will run further tests on this question to PartFSingletonTests GitlabTest.java
assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q14.txt
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Now is a good time to push your work to GitLab.
Question Fifteen (30 marks)
You may find parts of this question challenging. Take some time to conceptually understand the question, and reread it a couple of
times if you need to.
In this question, you will be implementing Java classes that can be used as a testing framework. Your solution should make use of Design
Patterns and constructs from the functional paradigm in a similar fashion to Lab 08: JQL.
The inspiration for this question is derived from , though no knowledge of Jest or JavaScript is required to the JavaScript testing framework Jest
complete this question.
You will be implementing a class which takes in a reference object of type in its construction. You will be able to use this class to Expect E
create 'expressions' comparing the reference object to other objects, such as equality, less than, or greater than or equal to.
Once the expression is constructed, you will be able to "evaluate" the expression. This will result in either:
ExpectationFailedException to be thrown, which is a which we have implemented for you; orRuntimeException
The expectation will pass, no exception is raised and nothing else will happen.
Here is a simple example of an expectation that passes:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("hello"); // Construct the expression
"hello" == "hello"
e2.evaluate() // The expression is true, no exception raised, nothing
happens
Here is a simple example of an expectation that fails:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("world"); // Construct the expression
"hello" == "world"
e2.evaluate() // The expression is false, a ExpectationFailedException
is raised
a) Basic Testing Operations (10 marks)
Inside , implement the following methods:q15/Expect.java
Constructor
public Expect(E obj)
Creates a new object and initialises values.Expect
toEqual
public Expect toEqual(E other)
Returns a new object with an expression testing whether the reference object is equal to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("hello"); // Construct the expression
"hello" == "hello"
lessThan
public> Expect
lessThan(T other)
Returns a new object with an expression testing whether the reference object is less than to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect(60); // Construct the base
expression
Expect e2 = e.lessThan(50); // Construct the expression 60 < 50
greaterThanOrEqualTo
public> Expect
greaterThanOrEqualTo(T other)
Returns a new object with an expression testing whether the reference object is greater than or equal to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect(60); // Construct the base
expression
Expect e2 = e.greaterThanOrEqualTo(50); // Construct the
expression 60 >= 50
evaluate
public void evaluate()
Evaluates an expression.Expect
If the expression that is being evaluated fails, an is thrown. The exception message string is up to you to ExpectationFailedException
define.
Example Usages:
Expect e = new Expect(50); // Construct the base
expression
Expect e2 = e.lessThan(60); // Construct the expression 50 < 60
e2.evaluate() // The expression is true, no exception raised, nothing
happens
Expect e3 = new Expect(50); // Construct the base
expression
Expect e4 = e.greaterThanOrEqualTo(60); // Construct the
expression 50 >= 60
e4.evaluate() // The expression is false, a ExpectationFailedException
is raised
When is called on a base object with no constructed expression, nothing happens, i.e:evaluate
Expect e = new Expect(1);
e.evaluate(); // Nothing happens
Other Notes
The behaviour of "chaining" multiple basic operations together such as , or is undefined, and toEqual lessThan greaterThanOrEqualTo
you don't have to worry about:
Expect e = new Expect(1);
Expect e2 = e.toEqual(1).lessThan(2).greaterThanOrEqualTo(3);
// undefined
HINT: The logic of each type of expression should be handled in the method.evaluate
Marking
A basic test for each of the above methods has been provided in within . We will run PartABasicOperationsTests ExpectTest.java
further tests on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (6 marks)
Design (4 marks)
b) Decoration Operations (7 marks)
In addition to "base-level" operations, decoration operations can be performed as well.
not
public Expect not()
Negates the decorated expectation. For example, when evaluated a would then become a "to not equal".toEqual
Expect e = new Expect("hello");
e.toEqual("world").not().evaluate(); // Expectation is true, no
exception is raised
skip
public Expect skip()
Skips all of the preceding operations, when evaluated nothing is run.
Expect e = new Expect("hello");
e.toEqual("world").skip().evaluate(); // Expectation is skipped, no
exception is raised
Other Notes
not and can be applied multiple times, for example:
Expect e = new Expect("hello");
Expect e2 = e.toEqual("world").not().not().not();
e2.evaluate(); // Expectation is true, no exception is raised
Expect e3 = new Expect("hello");
Expect e4 = e.toEqual("world").not().not().skip().skip();
e4.evaluate(); // Expectation is skipped, no exception is raised
No operations can be performed after a , e.g. , , are all skip e.skip().toEqual("today") e.skip().skip() e.skip().not()
undefined
A not operator cannot be the first expression, i.e. is undefined.e.not()
Marking
A basic test for each of the above methods has been provided within . We will run ExpectTests/PartBDecorationOperationsTests
further tests on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (3 marks)
c) Runnable Testing Operations (7 marks)
As well as basic functionality, good test frameworks provide the ability to assert the result of calls to runnable pieces of code.
The class inside has the following prototype:ExpectRunnable.java
class ExpectRunnable extends Expect
A is simply a lambda function which takes in no arguments and returns nothing.Runnable () -> ...
This type of expectation will wrap around a lambda and allow us to make assertions on the result of executing that lambda.
Inside , add and complete the following methods:ExpectRunnable
private ExpectRunnable()
Private constructor, no arguments.
public ExpectRunnable(E exec)
Public constructor, one argument - the runnable to be wrapped.
public ExpectRunnable toThrow(Class clz)
Takes in an object of type class, which is the type of exception that is expected to be thrown.
On evaluation, raises an if:ExpectationFailedException
No exception is thrown by the wrapped runnable
An exception is thrown by the wrapped runnable, but it is of a different class type to the one provided.
For example:
ExpectRunnable exec = new ExpectRunnable(() -> {
throw new RuntimeException("hello");
});
exec.toThrow(RuntimeException.class).evaluate();
You can think of this similarly to in the JUnit framework.assertThrows
public void execute() throws Throwable
Executes the inner runnable, throwing any exceptions.
A basic test for each of the above methods has been provided within . We will run further tests on this ExpectTests/PartCRunnableTests
question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (3 marks)
d) Parameterised Testing (6 marks)
You may find this part of the question particularly challenging.
Parameterised testing is a type of testing that allows you to improve the quality of your test code by abstracting away values and parameterising
them into variables.
In this part of the question, we will be writing an iterator that allows a user to parameterise tests.
The class inside has the following prototype:ExpectParameterised.java
class ExpectParameterised, L extends List>
implements Iterable
The class has the following constructor:
public ExpectParameterised(C consumer, L parameters)
C consumer, is an runnable function that takes in a value (the parameterised object) and returns nothingC extends Consumer
L parameters, is a list of parameters to pass into the functionL extends List
You will need to implement the following methods in the class:
public Iterator iterator()
public void evaluateAll() throws Throwable
To understand the usage of this class, let's have a look at the provided test:
ExpectParameterised, List> exp =
new ExpectParameterised, List>(
i -> {
Expect e = new Expect(i);
Expect e2 = e.lessThan(10); // Create expression i
< 10
e2.evaluate();
},
new ArrayList(Arrays.asList(8, 9, 10, 11)) // List of
parameters
);
Iterator iter = exp.iterator();
assertDoesNotThrow(() -> iter.next().run()); // 8 < 10, true
assertDoesNotThrow(() -> iter.next().run()); // 9 < 10, true
// 10 < 10, false - fails
assertThrows(ExpectationFailedException.class, () -> iter.next().run());
// 11 < 10, false - fails
assertThrows(ExpectationFailedException.class, () -> iter.next().run());
// Not all true, fails
assertThrows(ExpectationFailedException.class, () -> exp.evaluateAll());
A basic test for each of the above methods has been provided in within . We will run further tests PartDParameterisedTests ExpectTests
on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (2 marks)
Now is a good time to push what you have to GitLab.
End of Exam

















































withoutOddNumbers(List numbers) {
for (Integer number : numbers) {
if (number % 2 != 0) {
numbers.remove(number);
}
}
return new ArrayList(numbers);
}
Question Two (3 marks)
Part A (1 mark)
Select one or more of the following correct answers:
The dependency inversion principle encourages programming to ____________
An implementation, not an interface
An interface, not an implementation
Abstractions, not concretions
Concretions, not abstractions
A black box
A white box
Write your answer inside .q2.txt
Part B (2 marks)
Consider the class versus the class from the Blackout assignment, provided in and .Angle MathsHelper Angle.java MathsHelper.java
Which class do you think has better ? Justify your answer.cohesion
Write your answer inside .q2.txt
Question Three (4 marks)
In 22T3 COMP2511 is contemplating moving to Jira for students to manage their projects. There are three different types of Jira boards that can
be used: Scrum, Kanban and Bug Tracking. All boards have the same flow of work, and allow for features including support for issue tracking and
customisation of project-specific features. However, some elements may vary for each type of board - Scrum boards take two week sprints
whereas Kanban has a series of epics that are progressed through, and bug tracking projects only have a single backlog. Once a project is
created as Scrum, Kanban or Bug Tracking it cannot change its type.
What Design Pattern could be used to model this? In answering, justify your choice by describing how the above scenario relates to the key
of your chosen Design Pattern.characteristics
Write your answer inside .q3.txt
Question Four (2 marks)
Webster is waiting for tickets to be released to the next Sydney Swans game. He has setup notifications on his phone that will alert him when the
tickets open, and he is also checking his phone regularly since there are a limited number of tickets and he needs to be one of the first ones to
book to save a place.
Which implementation of the Observer Pattern is present in the above scenario, or ? Justify your answer.push pull
Write your answer inside .q4.txt
Question Five (3 marks)
Identify the code smells present in the following pieces of code, and explain whether you think this is indicative of an underlying design problem,
if so what the problem is, or alternatively if you think you don't have enough information to tell.
Write your answers inside .q5.txt
Part A (2 marks)
Scenario: A satellite simulation where various satellites are orbiting the Jovian ring.
private List standardSatellites;
private List quantumSatellites;
/**
** Run the simulation for a single minute
**/
public void simulate() {
// Update Position of Satellites
for (Satellite s : standardSatellites) {
s.setPosition(s.getPosition() + 3000 / s.getHeight());
}
for (Satellite s : quantumSatellites) {
s.setPosition(s.getPosition() + 2000 / s.getHeight());
}
// ... so on
}
Part B (1 mark)
public class ConsumeService {
// ...
public void startConsumeService(Config config, Consumer consumer,
Logger logger,
Tracer tracer, Metrics metrics,
String[] topics,
boolean willTimeout, int timeout) {
// ...
}
}
Question Six (3 marks)
During the project, a student on the forum asked the following question:
Are we allowed to modify the class given to us?Position
Tina answered the following:
Yes, so long as you don't break the preconditions and postconditions of that class - we will rely on these for automarking.
With reference to the Liskov Substitution Principle, explain what is meant by "breaking the preconditions and postconditions". Provide one
example (either breaking the preconditions or postconditions) of this with reference to the class, provided for you in and Position Position.java
explain how it would affect the automarking in this scenario.
Write your answer inside .q6.txt
You must answer two (2) out of the following six (6) choice questions.
Question Seven (3 marks)
Consider the following lambda function which checks if a number is prime. The type signature has been redacted.
[redacted] isPrime = n -> {
for (int i = 0; i < Math.sqrt(n); i++) {
if (n % i == 0) return false;
}
return true;
};
Which of the following answers could be correct? Out of these possible answers, explain which one is the most semantically correct.
a. Function
b. Function
c. Consumer
d. Consumer
e. Predicate
f. Predicate
g. Supplier
h. Supplier
Write your answer inside . Leave blank if you are not attempting this question.q7.txt q7.txt
Question Eight (3 marks)
During the project, Sienna and her group came up with the following testing plan:
To make sure our code is 100% correct, we will write unit tests for everything at the class level, and controller tests for
everything as well at the system level.
Here is an example of their test list for implementing battles:
Unit Tests Controller / System Tests
Test the player wins when battling a mercenary
Test the player loses when battling a mercenary
Test the player wins when battling a mercenary while invincible
Test the player wins when battling a zombie
Test the player loses when battling a zombie
Test the player wins when battling a zombie while invincible
Test the player wins when battling a spider
Test the player loses when battling a spider
Test the player wins when battling a spider while invincible
Test the player wins when battling a mercenary
Test the player loses when battling a mercenary
Test the player wins when battling a mercenary while invincible
Test the player wins when battling a zombie
Test the player loses when battling a zombie
Test the player wins when battling a zombie while invincible
Test the player wins when battling a spider
Test the player loses when battling a spider
Test the player wins when battling a spider while invincible
Explain why this is poor test design, and a possible alternative approach to testing.
Write your answer inside . Leave blank if you are not attempting this question.q8.txt q8.txt
1.
2.
Continue to Section 2 if you've answered two out of two choice questions already!
Question Nine (3 marks)
In a few days, Nick is going to run the automarker and download everyone's exam repositories. The script contains a simple loop which collect
downloads each student's repo, as follows. You can refer to the following pseudocode:
for student in students
print "==== Processing " + student + "===="
git clone path + "/" + student + "/exam.git" student
# more stuff
done
However, when multiple operations are run in close proximity by the same machine (usually around 10) Gitlab implements a git clone
protection strategy which blocks further s from being performed by that machine, in order to prevent someone launching a Denial of git clone
Service attack. When downloading repositories, however, this means that some operations fail. When the exam automarking is run, git clone
it is only run on the present folders and around 30 students won't receive their exam marks because of this error.
What was the flaw (or flaws) in this design? Explain two measures that could have been put in place to mitigate this from happening.
Write your answer inside . Leave blank if you are not attempting this question.q9.txt q9.txt
Question Ten (3 marks)
All software development is maintenance.
With reference to your project, in a paragraph or so, discuss the accuracy of the statement above.
Write your answer inside . Leave blank if you are not attempting this question.q10.txt q10.txt
Question Eleven (3 marks)
Liam is constructing a painting application, and has created a UML diagram which can be found in to model the domain.Q11-Quaint.pdf
Identify the Design Patterns used in Liam's implementation. (1 mark)
Pick of the design patterns and describe the how the implementation relates to the key characteristics of the design pattern. (2 marks)one
Write your answer inside . Leave blank if you are not attempting this question.q11.txt q11.txt
Question Twelve (3 marks)
In the asynchronous implementation of event-driven programming, Consumers and Producers communicate by reading from and writing to a
shared channel. Different types of events can flow through the channel, and Consumers and Producers can wear multiple hats - a Consumer can
also act as a Producer and vice-versa. In this case, when the entity consumes an event it immediately produces another event. Consumers
"subscribe" to events of a particular colour which are created by Producers.
Consider the following scenario where a Consumer C3, which consumes red events also acts as a Producer of red events.
Explain the problem caused by this design.
Write your answer inside . Leave blank if you are not attempting this question.q12.txt q12.txt
Now is a good time to push your work to GitLab.
Section 2: Extended Answer (10 marks)
Question Thirteen (10 marks)
Many online newspapers such as the provide a special type of article called a "live article", which uses the benefits of Sydney Morning Herald
real-time updating in the digital age to consistently provide new stories to readers throughout the day, each of these stories is called a (see post
below).
In this question, you will be designing, a system with the following functional requirements:but not implementing
A new live article can be created, storing the time it was first created;
A new can be made on the article, which includes the content, post title and a time the post was created;post
An existing post can have its content updated;
An existing post can be deleted
A comment can be made on a post
Model the domain for the above requirements to form the basis of a potential software solution. Your answer should include:
Interfaces, if applicable
Class Signatures, including inheritance relationships where appropriate
Method Signatures
Key Fields and relationships, including aggregations, compositions and cardinalities between entities (written as comments)
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 file.
An interface for the entire system has been provided to you in . You can modify these src/main/java/q13/LiveArticleSystem.java
method prototypes if you like, though you shouldn't need to.
There is a of undefined behaviour about this system, which is intentional. You can make as many assumptions as you need, so long as they lot
don't reduce the scope of the specification.
You will be assessed on:
Modelling of Entities (4 marks)
Aggregations, Compositions and Cardinalities (3 marks)
Modelling of Functionality (3 marks)
Try to spend around 10 minutes on this question to give yourself plenty of time for the Design & Programming section.
Now is a good time to push your work to GitLab.
Section 3: Design & Programming (65 marks)
Question Fourteen (35 marks)
In Lab 05: SSO, we looked at a system that handled . In this question, we will be dealing with in the context of a Authentication Authorisation
system that you have been working with - Gitlab.
In Gitlab, there are two types of "nodes" in a structural tree of permissions and access - and .groups projects
Groups are nodes that can contain projects, or other subgroups;
Projects are nodes that do not have any subgroups or subprojects, and act as a code repository (like this exam repo)
In the above example, the tree consists of the COMP2511 group which contains the 22T2 group, which contains STAFF group which contains
the tutor-notes project, other projects and another group called repos.
At each level, a user can have one of four different types of :permissions
Owner
Maintainer
Developer
1.
2.
3.
Reporter
For the purposes of this question, the only actions that will require permissions are:
Creating a project, which requires Developer permissions
Creating a subgroup, which requires Maintainer permissions
Changing the permissions of another member in the group, which requires Owner Permissions
Inside we have implemented a very basic system that addresses the above requirements. In this question you will be required src/q14/gitlab
to , , and .analyse the existing code make notes of design smells and refactor the code adapt the code to an evolution in the requirements
There are a series of regression tests that currently pass on the code in within .RegressionsTests GitlabTest.java
a) Code Analysis (5 marks)
Look at the code inside the package and in answer the following questions:gitlab q14.txt
Explain what Design Pattern is being used to represent the system, and how the domain relates to the key characteristics of the pattern. (2
marks)
Identify what you think is the main design problem present in the existing code, including what smells are indicating the problem. (2 marks)
Which of the following design smells is also present in the code? (1 mark)
Divergent Change
Inappropriate Intimacy
Refused Bequest
Message Chains
b) Refactoring a Method (3 marks)
Refactor the following method inside to use streams:GitlabGroup
public List getUsersOfPermissionLevel(PermissionsLevel level) {
Set membersSet = members.keySet();
List names = new ArrayList();
for (User member : membersSet) {
if (members.get(member).equals(level)) {
names.add(member.getName());
}
}
return names;
}
In your refactoring, you will need to keep the regression tests passing, which are provided in within .RegressionsTests GitlabTest.java
c) Refactoring the Design (9 marks)
Based on your notes on Design Smells from Part A, refactor the design of the system accordingly.
You can make any changes as you like, so long as you keep the regression tests passing, which are provided in within RegressionsTests Git
.labTest.java
Any notes you wish to make regarding your refactoring can go inside .q14.txt
The mark breakdown for this question is as follows:
Maintaining Correctness (1 mark)
Refactoring (8 marks)
d) Filtering Authorisation (9 marks)
Currently, there is a major flaw in our implementation - the system does not permissions from groups to all their subgroups and projects.filter
For example, if Claire is the owner of the COMP2511 group, then she is also the owner of the 22T2 group, the STAFF group and the tutor-notes
project and has the same Owner permissions on those groups as if she was a direct owner of those respective nodes.
Similarly, if a user tries to give permissions to another user on a group which, by filtering authorisation they have permissions on, a already Gitl
should be thrown.abAuthorisationException
In code, here is an illustration of the above description:
User user = new User("Claire");
User user2 = new User("Eddie");
// Create a group
GitlabPermissionsNode group = new GitlabGroup("COMP2511", user);
// Create a subgroup
GitlabPermissionsNode group2 = assertDoesNotThrow(() -> group.
createSubgroup("22T2", user));
// Give dev access to Eddie on the COMP2511 group
assertDoesNotThrow(() -> group.updateUserPermissions(user2,
PermissionsLevel.DEVELOPER, user));
// Check that Eddie also has dev access on the 22T2 group
assertEquals(PermissionsLevel.DEVELOPER, group2.getUserPermissions
(user2));
// Try to give Eddie reporter access on the 22T2 group, but he is
already a developer of COMP2511
// so an authorisation error is thrown
assertThrows(GitlabAuthorisationException.class,
() -> group2.updateUserPermissions(user2, PermissionsLevel.
REPORTER, user));
Implement the 'filtering' of authorisation. A basic test has been provided to you in within PartDFilteringAuthorisationTests GitlabTest.
. We will run further tests on this question to assess the correctness of your solution.java
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Any notes you wish to make regarding your design can go inside .q14.txt
You need to complete (1) out of the following (2) choice parts of this question.one two
e) Factory Pattern (9 marks)
Inside , implement the following method:GitlabFactory.java
public static GitlabPermissionsNode gitlabFromJson(String jsonString,
User user)
The method should take in a string of the following format:gitlabFromJson
{
"type": "group",
"name": "COMP2511",
"subgroups": [
{
"type": "group",
"name": "22T2",
"subgroups": [
{
"type": "project",
"name": "dungeonmania"
}
]
},
{
"type": "project",
"name": "blackout"
}
]
}
and produce a with the corresponding structure. You do not need to handle any processing of group/project GitlabPermissionsNode
members in this part of the question.
A basic test has been provided to you in within . We will run further tests on this question to assess PartEFactoryTests GitlabTest.java
the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q14.txt
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Continue to Question Fifteen if you have already completed Part E!
f) Singleton Pattern (9 marks)
All projects in Gitlab run their pipelines on a single machine, which is why the runner gets very slow around project and assignment deadlines.
Currently, the method inside , which takes in an runnable "process" creates a new instance of the runner and runPipeline GitlabProject
runs the job.
public void runPipeline(Runnable job) {
GitlabRunner runner = new GitlabRunner();
runner.run(job);
}
Refactor the code to use the so that only one instance of the exists and only one job is able to run at a time (i.Singleton Pattern GitlabRunner
e. only one call can be made at a time).run
A basic test has been provided to you in within . We will run further tests on this question to PartFSingletonTests GitlabTest.java
assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q14.txt
The mark breakdown for this question is as follows:
Correctness (5 marks)
Design (4 marks)
Now is a good time to push your work to GitLab.
Question Fifteen (30 marks)
You may find parts of this question challenging. Take some time to conceptually understand the question, and reread it a couple of
times if you need to.
In this question, you will be implementing Java classes that can be used as a testing framework. Your solution should make use of Design
Patterns and constructs from the functional paradigm in a similar fashion to Lab 08: JQL.
The inspiration for this question is derived from , though no knowledge of Jest or JavaScript is required to the JavaScript testing framework Jest
complete this question.
You will be implementing a class which takes in a reference object of type in its construction. You will be able to use this class to Expect E
create 'expressions' comparing the reference object to other objects, such as equality, less than, or greater than or equal to.
Once the expression is constructed, you will be able to "evaluate" the expression. This will result in either:
ExpectationFailedException to be thrown, which is a which we have implemented for you; orRuntimeException
The expectation will pass, no exception is raised and nothing else will happen.
Here is a simple example of an expectation that passes:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("hello"); // Construct the expression
"hello" == "hello"
e2.evaluate() // The expression is true, no exception raised, nothing
happens
Here is a simple example of an expectation that fails:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("world"); // Construct the expression
"hello" == "world"
e2.evaluate() // The expression is false, a ExpectationFailedException
is raised
a) Basic Testing Operations (10 marks)
Inside , implement the following methods:q15/Expect.java
Constructor
public Expect(E obj)
Creates a new object and initialises values.Expect
toEqual
public Expect toEqual(E other)
Returns a new object with an expression testing whether the reference object is equal to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect("hello"); // Construct the base
expression
Expect e2 = e.toEqual("hello"); // Construct the expression
"hello" == "hello"
lessThan
public> Expect
lessThan(T other)
Returns a new object with an expression testing whether the reference object is less than to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect(60); // Construct the base
expression
Expect e2 = e.lessThan(50); // Construct the expression 60 < 50
greaterThanOrEqualTo
public> Expect
greaterThanOrEqualTo(T other)
Returns a new object with an expression testing whether the reference object is greater than or equal to the provided object.Expect
This method does not raise any exceptions.
Example Usage:
Expect e = new Expect(60); // Construct the base
expression
Expect e2 = e.greaterThanOrEqualTo(50); // Construct the
expression 60 >= 50
evaluate
public void evaluate()
Evaluates an expression.Expect
If the expression that is being evaluated fails, an is thrown. The exception message string is up to you to ExpectationFailedException
define.
Example Usages:
Expect e = new Expect(50); // Construct the base
expression
Expect e2 = e.lessThan(60); // Construct the expression 50 < 60
e2.evaluate() // The expression is true, no exception raised, nothing
happens
Expect e3 = new Expect(50); // Construct the base
expression
Expect e4 = e.greaterThanOrEqualTo(60); // Construct the
expression 50 >= 60
e4.evaluate() // The expression is false, a ExpectationFailedException
is raised
When is called on a base object with no constructed expression, nothing happens, i.e:evaluate
Expect e = new Expect(1);
e.evaluate(); // Nothing happens
Other Notes
The behaviour of "chaining" multiple basic operations together such as , or is undefined, and toEqual lessThan greaterThanOrEqualTo
you don't have to worry about:
Expect e = new Expect(1);
Expect e2 = e.toEqual(1).lessThan(2).greaterThanOrEqualTo(3);
// undefined
HINT: The logic of each type of expression should be handled in the method.evaluate
Marking
A basic test for each of the above methods has been provided in within . We will run PartABasicOperationsTests ExpectTest.java
further tests on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (6 marks)
Design (4 marks)
b) Decoration Operations (7 marks)
In addition to "base-level" operations, decoration operations can be performed as well.
not
public Expect not()
Negates the decorated expectation. For example, when evaluated a would then become a "to not equal".toEqual
Expect e = new Expect("hello");
e.toEqual("world").not().evaluate(); // Expectation is true, no
exception is raised
skip
public Expect skip()
Skips all of the preceding operations, when evaluated nothing is run.
Expect e = new Expect("hello");
e.toEqual("world").skip().evaluate(); // Expectation is skipped, no
exception is raised
Other Notes
not and can be applied multiple times, for example:
Expect e = new Expect("hello");
Expect e2 = e.toEqual("world").not().not().not();
e2.evaluate(); // Expectation is true, no exception is raised
Expect e3 = new Expect("hello");
Expect e4 = e.toEqual("world").not().not().skip().skip();
e4.evaluate(); // Expectation is skipped, no exception is raised
No operations can be performed after a , e.g. , , are all skip e.skip().toEqual("today") e.skip().skip() e.skip().not()
undefined
A not operator cannot be the first expression, i.e. is undefined.e.not()
Marking
A basic test for each of the above methods has been provided within . We will run ExpectTests/PartBDecorationOperationsTests
further tests on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (3 marks)
c) Runnable Testing Operations (7 marks)
As well as basic functionality, good test frameworks provide the ability to assert the result of calls to runnable pieces of code.
The class inside has the following prototype:ExpectRunnable.java
class ExpectRunnable extends Expect
A is simply a lambda function which takes in no arguments and returns nothing.Runnable () -> ...
This type of expectation will wrap around a lambda and allow us to make assertions on the result of executing that lambda.
Inside , add and complete the following methods:ExpectRunnable
private ExpectRunnable()
Private constructor, no arguments.
public ExpectRunnable(E exec)
Public constructor, one argument - the runnable to be wrapped.
public ExpectRunnable toThrow(Class clz)
Takes in an object of type class, which is the type of exception that is expected to be thrown.
On evaluation, raises an if:ExpectationFailedException
No exception is thrown by the wrapped runnable
An exception is thrown by the wrapped runnable, but it is of a different class type to the one provided.
For example:
ExpectRunnable exec = new ExpectRunnable(() -> {
throw new RuntimeException("hello");
});
exec.toThrow(RuntimeException.class).evaluate();
You can think of this similarly to in the JUnit framework.assertThrows
public void execute() throws Throwable
Executes the inner runnable, throwing any exceptions.
A basic test for each of the above methods has been provided within . We will run further tests on this ExpectTests/PartCRunnableTests
question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (3 marks)
d) Parameterised Testing (6 marks)
You may find this part of the question particularly challenging.
Parameterised testing is a type of testing that allows you to improve the quality of your test code by abstracting away values and parameterising
them into variables.
In this part of the question, we will be writing an iterator that allows a user to parameterise tests.
The class inside has the following prototype:ExpectParameterised.java
class ExpectParameterised, L extends List>
implements Iterable
The class has the following constructor:
public ExpectParameterised(C consumer, L parameters)
C consumer, is an runnable function that takes in a value (the parameterised object) and returns nothingC extends Consumer
L parameters, is a list of parameters to pass into the functionL extends List
You will need to implement the following methods in the class:
public Iterator iterator()
public void evaluateAll() throws Throwable
To understand the usage of this class, let's have a look at the provided test:
ExpectParameterised, List> exp =
new ExpectParameterised, List>(
i -> {
Expect e = new Expect(i);
Expect e2 = e.lessThan(10); // Create expression i
< 10
e2.evaluate();
},
new ArrayList(Arrays.asList(8, 9, 10, 11)) // List of
parameters
);
Iterator iter = exp.iterator();
assertDoesNotThrow(() -> iter.next().run()); // 8 < 10, true
assertDoesNotThrow(() -> iter.next().run()); // 9 < 10, true
// 10 < 10, false - fails
assertThrows(ExpectationFailedException.class, () -> iter.next().run());
// 11 < 10, false - fails
assertThrows(ExpectationFailedException.class, () -> iter.next().run());
// Not all true, fails
assertThrows(ExpectationFailedException.class, () -> exp.evaluateAll());
A basic test for each of the above methods has been provided in within . We will run further tests PartDParameterisedTests ExpectTests
on this question to assess the correctness of your solution.
Any notes you wish to make regarding your design can go inside .q15.txt
The mark breakdown for this question is as follows:
Correctness (4 marks)
Design (2 marks)
Now is a good time to push what you have to GitLab.
End of Exam

学霸联盟


essay、essay代写