School of Science, Computing and Engineering Technologies
Object Oriented Programming
Hurdle Task 1: Semester Test
Overview
Note: This hurdle task is a time-bound test. You have a 48 hour window during week 8
to complete it.
- If you receive a Complete grade, you have passed the hurdle and can include the
test as evidence of that in your portfolio.
- If you receive a Fix grade, you must correct all issues and get your test signed off as
Complete to meet the hurdle requirements. If you do not get it marked as Complete dur-
ing the teaching period, you must include a copy of your corrections in your portfolio to
demonstrate that you have addressed the issues raised. Failure to do this will result in
an overall fail grade for the unit.
- If you receive a Redo grade, you must pass a re-sit test that will occur in week 12 in
order to meet the hurdle requirements.
In this unit, you have been using object-oriented programming to implement all of your pro-
grams. For this task, you will need to show your understanding of the OO principles.
Purpose: Demonstrate your understanding of object-oriented programming and the
core concepts of object-oriented design.
Task: You must complete two tasks. The first is a coding task, to be submitted as
C# source code files, a UML diagram, and a screenshot showing your pro-
gram’s output. The second task asks for a written response, to be submitted
as a PDF.
Time: This task should be completed during week 8 — see Canvas for the assign-
ment window.
Submission Details
You must submit the following files:
■ For Task 1:
■ C# code files of the classes created
■ An image file showing your modified design as a UML class diagram
■ A screenshot of the program output
■ For Task 2:
■ A PDF document with your answer
Make sure that you submit code that is readable and is appro-
priately documented.
Object Oriented Programming Hurdle Task 1 - Semester Test
Task 1
Consider the following program design:
DataAnalyser
- _numbers : List<Int>
- _avgSummariser : AverageSummary
- _minMaxSummariser : MinMaxSummary
+ DataAnalyser()
+ DataAnalyser(List<int> numbers)
+ AddNumber(int num)
+ Summarise(string typeOfSummary)
AverageSummary MinMaxSummary
- Average(List<int> numbers) : float - Minimum(List<int> numbers) : int
- Maximum(List<int> numbers) : int
+ PrintAverage(List<int> numbers)
+ PrintMinMax(List<int> numbers)
DataAnalyser is a class that can print a summary of a list of numbers. Those numbers can be
initialised through the constructor with a parameter, or alternatively be added using the Add-
Number method after object initialisation.
Currently there are two ways of summarising the data. These two ways are implemented in the
AverageSummary and MinMaxSummary classes. As their names suggest, AverageSummary
calculates the average value of the list, and MinMaxSummary prints out the minimum and
maximum values of the list.
At the moment, the DataAnalyser can be asked to summarise its list of numbers with a call to
its Summarise method. This method accepts a single parameter, which indicates which sum-
mary method should be used. If the parameter’s value is “average”, it should use the average
summary. If the value is “minmax”, it should use the minmax summary. The casing of the value
should not matter (e.g., passing in the value of “aVeraGE” should result in the same behaviour
as passing in the value “average”).
Your task is to redesign this program to better follow the principles of object-oriented pro-
gramming, focusing on the concept of polymorphism. To do this, you should restructure the
program to use an abstract SummaryStrategy class. This class should adhere to the follow-
ing UML design:
<<abstract>>
SummaryStrategy
+ PrintSummary(List<int> numbers) <<abstract>>
Page 2 of 4
Object Oriented Programming Hurdle Task 1 - Semester Test
To implement this new class and integrate it with our existing design, the following changes
need to be made:
1. Implement the SummaryStrategy abstract class according to the above design.
2. Redesign and implement the AverageSummary and MinMaxSummary classes to be
child classes of the new SummaryStrategy class.
3. Modify DataAnalyser to have a private variable, “_strategy”, that is of the type Summa-
ryStrategy.
4. Add a public property for this new private variable.
5. Modify the DataAnalyser constructors to:
a) allow the strategy to be set through a parameter
b) by default (i.e., if there are no parameters), set the strategy to the average strategy.
6. Modify DataAnalyser’s Summarise method to use the currently stored strategy instead of
relying on a string parameter.
7. Write a simple Main method to demonstrate how your new design works:
a) Create a DataAnalyser object with a list containing the individual digits of your student
ID (so if your student ID was 12345, the list would contain the numbers 1, 2, 3, 4, and
5), and the minmax summary strategy.
b) Call the Summarise method.
c) Add three more numbers to the data analyser.
d) Set the summary strategy to the average strategy.
e) Call the Summarise method.
Tip: Subclasses need to adhere to the requirements of the parent, but they can still add
their own additional functionality. Consider how the code can be broken up so that the
methods in your classes have just one purpose and no side effects.
You are required to:
a) Provide a new UML class diagram for your updated design (hand drawn is fine).
b) Write the code for all classes, including the SummaryStrategy abstract class, and all
methods/fields/constructors required.
c) Write the average, minimum, and maximum summary algorithms without using any addi-
tional libraries.
d) Write a simple Main method as described above.
Submit a photo or image of your UML, all source code files, and a screenshot showing your
program working.
Page 3 of 4
Object Oriented Programming Hurdle Task 1 - Semester Test
Task 2
1. Describe the principle of polymorphism and how it was used in Task 1.
2. Using an example, explain the principle of abstraction.
3. What was the issue with the original design in Task 1? Consider what would happen if we
had 50 different summary approaches to choose from instead of just 2.
Tip: In object-oriented programming we have talked about the concepts of abstraction
and abstract classes. Remember that they are different, and we are asking you to ex-
plain the first one!
Note: Write your answer in your own words. You can use as many reference materi-
als as you like, but you must not directly copy text from anywhere.
Submit your answer as a PDF document.
Page 4 of 4