The objective of this assessment is for you to demonstrate your ability to design and implement an OO system consisting of a set of Java classes and a client program. In particular:
1. To design and implement classes with suitable fields, constructors, accessor methods, and modifier methods.
2. To conform to the standard conventions of Java.
3. To implement classes that are associated by inheritance, delegation, composition, and aggregation.
4. To write a client application that uses your classes to show that they function correctly.
Assignment 3
Faculty of Technology – Course work Specification 2020/21
Module name:
Object Oriented Programming
Module code:
Title of the Assignment:
Assignment 3
This coursework item is:
Summative
This summative coursework will be marked anonymously
No
The learning outcomes that are assessed by this coursework are:
1. Have a comprehensive understanding of OO programming concepts: abstraction, encapsulation,
inheritance, etc.
2. Be able to select appropriate API facilities in the design, implementation and testing of OO applications and applets.
1.
Page 1 of 9
Assignment 3
Assessment 3
About this assessment
This individual summative assessment counts 50% towards your module mark. You are given a scenario for
your assignment. This takes the form of a design description and a specification by way of a class diagram.
You should gain an understanding of the scenario, implement the class diagram, and produce the
functionality listed within the use cases.
You should implement each class to the expected standards as discussed and practiced during the module.
Objectives
The objective of this assessment is for you to demonstrate your ability to design and implement an OO
system consisting of a set of Java classes and a client program. In particular:
1. To design and implement classes with suitable fields, constructors, accessor methods, and modifier
methods.
2. To conform to the standard conventions of Java.
3. To implement classes that are associated by inheritance, delegation, composition, and aggregation.
4. To write a client application that uses your classes to show that they function correctly.
Submission
Submit one .zip Archive File called Assignment3_PNumber.zip via Blackboard consisting of your (Eclipse)
project folder. Make sure all your source code is in there.
P.T.O.
Page 2 of 9
Assignment 3
Your Scenario: Hospital Booking System
[Section I – 80%] When making appointment to visit the hospital, a Patient with Name and patientID makes
an Appointment with a Doctor. The Doctor can either by a ConsultantDoctor or JuniorDoctor. After
diagnosis, the Doctor will give the Patient a Prescription with Medication or DiscountedMedication and
price of each. The content of Prescription can be sorted in various ways and total cost can be calculated.
Medications in a Prescription can be iterated over and tested for equality.
The partial UML class diagram below shows the underlying data model you should use to achieve this
scenario:
Page 3 of 9
Assignment 3
The table below gives further guidance on the implementation of each class:
Class
Comment
Name
Simple name comprising a first name and family name.
Date
Simple date record with day/month/year fields. Validate on update
Patient
A Patient has a name, unique ID, and age.
Patient can be tested for equality by providing an appropriate overridden
equals(…) method that assesses the equality of ID field.
Additionally, products are comparable, so they can be sorted into a natural order.
They should firstly be compared by product code, if these are the same, then by
description, and if these are the same, then by unit price.
Doctor
An abstract class with unique id, Name, and department. It also has an abstract
method generateDoctorID() that generates the doctorID and returns it
ConsultantDoctor
A Consultant Doctor is a Doctor with specialization and can be a team leader or
not.
When generating the doctorID, it should start with “C”, followed by 4-digit
random number (e.g. C1234). You are expected to use the java.util.Random class
in doing this
JuniorDoctor
A Junior Doctor is assigned to a single team.
When generating the doctorID, it should start with “J”, followed by 4-digit random
number (e.g. J1234). You are expected to use the java.util.Random class in doing
this
Medication
A Medication has a name, unique ID, and fixed price (irrespective of quantity).
One medication can have different price (e.g. Paracetamol for children is £3.50,
but same paracetamol for adults is £3.80).
Medication can be tested for equality by providing an appropriate overridden
equals(…) method that assesses the equality of ID field and fixed price.
Additionally, Medication are comparable, so they can be sorted into a natural
order. They should firstly be compared by Medication id, if these are the same,
then by price.
DiscountedMedica
tion
A Discounted Medication is a Medication with a discount rate applied. The
discount rate should be between 0 and 1.0, with 0.1 being a 10% discount, 0.2
being a 20% discount, etc.
When retrieving the price of a discount Medication it should return the standard
price with any discount applied. A discount amount should always be to 2 decimal
place, e.g. a calculated discount of £7.988686 would apply as a discount of £7.99
on the unit.
Page 4 of 9
Assignment 3
Appointments
An Appointment is made by a Patient for a specified
An Appointment can be tested for equality – an Appointment is equal to another
if its associated Patient and date is the same.
Appointments can be filtered by ID to find a specific Appointment.
Appointments can be filtered by patientID to find all appointments made by a
Patient
Prescription
A Prescription is for an appointment and has a unique id. It consists of a list of
medications, and the doctor that made the prescription. It has a set of methods
to add/remove and retrieve a medication so that it can be modified or printed on
a receipt, for example. The total cost of the Prescription is given by the getCost()
method. An Prescription can be searched for by medicationid.
A Prescription should also allow its orders to be sorted into their natural order via
a sortMedication() method. It should provide an additional overloaded method
sortMedication(Comparator) that accepts a custom comparator
and applies this to the list of orders.
The Prescription requires two further methods: containsMedication and
removeMedication, as shown in the UML diagram, that will make use of an
equality test.
A Prescription should also provide an iterator over its Medications.
Use Cases: You should have a test class, with a main method, that should complete the following use
cases for the “Shopping Cart System” to show it works as expected. Please clearly highlight where each
use case is exercised in your test program with comments:
PrescriptionTest
UC1: A test program that creates 2 instances of Prescription, populates them with
several Medication (for both Medication and discounted medication), and uses a
for-each loop to produce a formatted listing of the medications with their price,
the number of items in the prescription and the overall total price.
Note: You can either use a data file to dynamically read Medication or hard-code
the Medication instances to add to the Prescription.
UC2: Test each of the sort methods work as expected, as evidenced by appropriate output.
•
For the sortMedication(Comparator) method, you
should pass in a custom comparator that sorts by price (asc) and if
these are the same then by Medication name (desc).
UC3: Additionally, test the use of equality by using the contains and remove methods. Also, you should use a PrintWriter to produce a receipt for all of the Medication and associated details of the Prescription, and output these into a text file
Prescription.txt.
UC4: Add further code to show how each method of Prescription can be used. In
particular, add or remove one or more of the Medications in the Prescription, and
Page 5 of 9
Assignment 3
then re-print the updated Prescription listing.
Please turn over…
Page 6 of 9
Assignment 3
[STAGE 2 – 20%] When prescription is given, reward points may be gained if the patient is a child (under 18
years) or aged (older than 65 years) and prescribed some selected medications. A reward processor holds a
collection of each Medication for which points should be awarded, and can process a shopping Prescription
to ascertain its contents and apply any necessary awards.
The partial UML class diagram below shows some updates to the underlying data model. Please note: The
Patient and Medication classes should remain as before, but should include any additional implementation
details as shown in the UML diagram.
The table below gives further guidance:
Class
Comment
Patient
A Patient now has a field to hold their reward points, a means of adding these,
and retrieving their current quota of points.
RewardProcessor
A reward processor should store Medication, which can gain rewards for the
Patient if they are in their Prescription. A hash set collection should be used for
this. The rewardPoints(Prescription) method checks if a rewardable Medication is
in the Prescription, and if so adds points to the Prescription’s Patient. The number
of points to be added should be the 1 of each Medication. The method should
return the total number of reward points that have been awarded to the Patient
for this Prescription.
Note: you may need to do some research into how to use a HashSet collection in
Java.
Use Cases: Add the following use case at the end of your existing code in your test program – you may
need to update other code that has been affected by the additional changes.
PrescriptionTest
UC5: Create an instance of RewardProcessor, add a selection of Medication to it
(but not all the same as those in your Prescription), and then test the rewardPoints method appropriately.
Page 7 of 9
Assignment 3
IMAT5101 Assignment 3 Assessment Indicators
Distinction(70%+): As for Merit above. Additionally: a coherent data model has been designed and
implemented, with appropriate levels of abstraction. Any additional specified functionality has been added,
with creativity beings shown. The integrity of fields has been a consideration and mostly maintained. All usecases have been implemented with high levels of success. Documentation is at the appropriate level to
support maintainable code. All the lab test activities have been completed successfully and demonstrate the
correctness and quality of the system.
Please Turn Over for a Checklist of Assessment Indicators.
Page 8 of 9
Assignment 3
Checklist
These indicators will be used as a basis for the assessment mark and will form your feedback.
(70% Model) Class documentation, design, and implementation.
•
Javadoc class headers, method and constructor descriptions, and use of @tags. [Stage 1]
•
Fields, constructors, and standard methods – (adhering to standard Java conventions). [Stage 1]
•
Correct implementation of associations (Composition, Aggregation, and Inheritance). [Stage 1]
•
Appropriate overridden implementations of the equals(…) method. [Stage 1]
•
Use of common Interface types, e.g. Iterable, Comparable, Comparator. [Stage 1]
•
Implementation of reward points, and a hash-based collection. [Stage 2]
•
Implementation of price policies, using a functional interface. [Stage 3]
(30% Testing) Use Case success.
•
Use Case 1 has been achieved appropriately. [Stage 1]
•
Use Case 2 has been achieved appropriately. [Stage 1]
•
Use Case 3 has been achieved appropriately. [Stage 1]
•
Use Case 4 has been achieved appropriately. [Stage 1]
•
Use Case 5 has been achieved appropriately. [Stage 2]
For each use case the overall quality of test data and output will be considered.
Page 9 of 9