Assessment: This Part 2 of the assignment is worth 15% of the final mark for this subject.
Due Date: Monday 28 May 2018 at 10.00 am
Delays caused by computer downtime cannot be accepted as a valid reason for a late submission
without penalty. Students must plan their work to allow for both scheduled and unscheduled
downtime. Penalties are applied to late assignments, accepted up to 5 days after the due date only.
Individual Assignment: This is an individual assignment. You are not permitted to work as a
group when writing this assignment.
Copying, Plagiarism: Plagiarism is the submission of somebody else’s work in a manner that
gives the impression that the work is your own. The Department of Computer Science and Com-
puter Engineering treats academic misconduct seriously. When it is detected, penalties are strictly
imposed.
Objectives: The general aims of this assignment are:
• To analyze a problem in an object-oriented manner, and then design and implement an
object-oriented solution that conforms to given specifications
• To practise using inheritance in Java
• To practise file input and output in Java
• To make implementations more robust through mechanisms such as exception handling.
Submission Details and Marking Scheme: Instructions on how to submit electronic copies of
your source code files from your latcs8 account and a marking scheme overview are given at the
end.
If you have not been able to complete a program that compiles and executes containing all func-
tionality, then you should submit a program that compiles and executes with as much functionality
as you have completed. You may comment out code that does not compile. However, the com-
mented out code will not be marked.
Deployment Platform. While you are free to develop the code for this assignment on any
operating system, your solution must run on the latcs8 system. We should be able to compile
your classes with the simple command javac *.java, and execute your programs with a simple
command, e.g. java PatientRecordSystemMenu.
Background
As described in the handout for Part 1, the overall aim of the assignment is to develop a prototype
for a patient record system.
In Part 1, you have implemented the classes to represent patients, medical observation types, and
observations. You have also implemented a PatientRecordSystem class which allows us to add
patients, observation types and observations.
Building on the work that you have done for part 1, in this Part 2, you are required to do the tasks
described below.
Essentially, you will
• expand on the functionality of the classes that you have developed in Part 1, and
• implement a menu program
Besides the information given in the tasks below, please refer to Part 1 of the Assignment for other
information you need.
Task 1
Implement two methods for the PatientRecordSystem class to save data and to ld data.
The first method, with the header
public void saveData() throws Exception
will save the data to five text files:
• PRS-MeasurementObservationTypes.txt
This file saves the measurement observation types. A sample is shown below:
T100; Blood Pressure; psi
T400; Height; cm
Each measurement observation type is on a separate line. It contain the observation type code,
name and unit, separated by semi-colons.
• PRS-CategoryObservationTypes.txt
This file saves the category observation types. A sample is shown below:
T200; Blood Type; Group A, Group B1, Group B2
T300; Stress Level; Low, Medium, High
Each category observation type is on a separate line. It contain the observation type code, name
and the categories. The three “fields” code, the name and the categories are separated by semi-
colons. In the categories field, the categories are separated by commas.
• PRS-Patients.txt
This file saves the patients’s data without their observations. A sample is shown below:
P100; John Smith
P200; Anna Bell
Each patient is on a separate line. It contain the patient’s id and name, separated by a semi-
colon.
2
• PRS-MeasurementObservations.txt
This file saves the patients’s measurement observations. A sample is shown below:
P100; T100; 120.0
P200; T400; 180
Each measurement observation is on a separate line. It contain the patient’s id, the observation
code and the observation value (a double). The fields are separated by semi-colons.
• PRS-CategoryObservations.txt
This file saves the patients’s category observations. A sample is shown below:
P100; T200; Group A
P200; T300, Low
Each measurement observation is on a separate line. It contain the patient’s id, the observation
code and the observation value (a double). The fields are separated by semi-colons.
The second method, with the header
public void loadData() throws Exception
will read the data from five text files and save them in a PatientRecordSystem instance by
calling methods to add measurement observation types, category observation types, etc.
The data should be loaded into a PatientRecordSystem instance which is empty of data.
Of course, you may need to enhance other classes to support the implementation of the saveData
and loadData methods.
Also, you should write a small program to test your methods. A sample test program is given in
the Appendix 1.
As for Part 1, your implementation must be such that the sample test program can be run
without any change.
The sample test program is more or less the bare minimum. You should add more test cases to it.
3
Task 2
Write the menu program, called PatientRecordSystemMenu, to provide options in the following
menu:
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by the patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X):
The menu program must use the PatientRecordSystem class developed for Task 1.
For each option, the program should ask for the required inputs, each with a separate prompt.
For option 6, 7 and D, it is acceptable just to use the toString methods of the classes involved
(which should have been implemented in Part 1 of the assignment).
See Appendix 2 for a short sample run.
The menu program for this task is only required to satisfy the data correctness conditions. It is not
required to be robust, i.e. it can crash when certain exceptions occur.
Task 3- Making the Menu Program Robust
Implement a class called RobustPatientRecordSystemMenu, which extends the previous menu
and includes enough exception handling features to make it robust. It is required to be robust only
in the following sense: when an exception occurs in the execution of an option, the program will
display some information about the exception on the screen and return to the min menu.
Task 4. (For CSE4IOO students only)
This task is not related to the Patient Record System. For the purpose of this task, a string is
regarded as having the correct syntax for an email if it satisfies the following conditions:
• Condition 1: It is a sequence of lowercase letters, the period character (’.’), and the @
character
• Condition 2: The @ character must appear once and must appear between two letters
• Condition 3; The period character can appear zero or more times, and it must appear between
two letters
4
Write an EmailChecker class, which has methods with headers:
• public static boolean checkCharacters(String email)
which returns true if Condition 1 is satisfied, and false otherwise
• public static boolean checkAt(String email)
which returns true if Condition 2 is satisfied, and false otherwise
• public static boolean checkDot(String email)
which returns true if Condition 3 is satisfied, and false otherwise
• public static boolean checkEmail(String email)
which returns true if the string has the valid format for an email, and false otherwise.
Submit the EmailChecker and a EmailCheckerTestter class.
(The total mark for Part 2 will be 100 for CSE1IOO students and 110 for CSE4IOO students. The
percentage of contribution to the final will be the same.)
Electronic Submission of the Source Code
• Submit all the Java files that you have developed in the tasks above.
• The code has to run under Unix on the latcs8 machine.
• You submit your files from your latcs8 account. Make sure you are in the same directory as
the files you are submitting.
• Submit each file separately using the submit command. For example, for the file called (say)
ObservationType.java, use command:
submit IOO ObservationType.java
• After submitting the files, you can run the following command that lists the files submitted
from your account:
verify
• You can submit the same filename as many times as you like before the assignment deadline;
the previously submitted copy will be replaced by the latest one.
Marking Scheme Overview
Implementation (Execution of code) 90% (Do all parts of the programs execute correctly? Note
your programs must compile and run to carry out this implementation marking.)
Program Design and Coding Style. 10% (Does the program conform. to specifications? Does the
program solve the problem in a well-designed manner? Does the program follow good program-
ming practices? Does the indentation and code layout follow a good, consistent standard? Are the
identifiers meaningful? Are comments being used effectively?)
5
Return of Assignments
Assignments are to be returned within 3 weeks of the submission date. Students will be notified by
email and via the CSE1/CSE4IOO website news when marking sheets are available for collection.
Appendix 1 – A Program to Test Methods to Save and Load Data
import java.io.*;
import java.util.*;
public class PatientRecordSystemTester
{
public static void main(String [] args) throws Exception
{
testSaveData();
testLoadData(); // this method calls testSaveData ()
}
public static void testSaveData() throws Exception
{
// Create PatientRecordSystem
// Add observation types , patients and observations
PatientRecordSystem prs = new PatientRecordSystem();
prs.addMeasurementObservationType("T100", "Blood Pressure", "psi");
String [] categories = {"Group A", "Group B1", "Group B2"};
prs.addCategoryObservationType("T200", "blood type", categories);
String [] temp = {"low", "Medium", "high"};
categories = temp;
prs.addCategoryObservationType("T300", "stress level", categories);
prs.addMeasurementObservationType("T400", "height", "cm");
prs.addPatient("P100", "Smith");
prs.addPatient("P200", "Adams");
prs.addMeasurementObservation("P100", "T100", 120);
prs.addCategoryObservation("P100", "T200", "Group A");
// save data to file
prs.saveData();
}
public static void testLoadData() throws Exception
{
testSaveData();
PatientRecordSystem prs = new PatientRecordSystem();
prs.loadData();
System.out.println(prs);
}
}
6
Appendix 2 – A Sample Run of the Menu Program
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): 2
Enter observation type code: t1
Enter observation type name: stress level
Enter the number of categories: 3
Enter category 1: low
Enter category 2: medium
Enter category 3: high
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): d
--------------------------
PATIENT RECORD SYSTEM DATA
--------------------------
OBSERVATION TYPES:
-- CategoryObservationType[code: t1, name: stress level, categories: |low|m
edium|high|]
PATIENTS:
Please press the ENTER key to continue:
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
7
X. Exit
Please enter an option (1-9 or D or X): 3
Enter patient ID: p1
Enter patient Name: john smith
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): d
--------------------------
PATIENT RECORD SYSTEM DATA
--------------------------
OBSERVATION TYPES:
-- CategoryObservationType[code: t1, name: stress level, categories: |low|m
edium|high|]
PATIENTS:
-- Patient id: p1, name: john smith
Observations:
Please press the ENTER key to continue:
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): 5
Enter patient ID: p1
Enter observation type code: t1
Enter observation type value: medium
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): d
--------------------------
PATIENT RECORD SYSTEM DATA
--------------------------
OBSERVATION TYPES:
-- CategoryObservationType[code: t1, name: stress level, categories: |low|m
edium|high|]
PATIENTS:
-- Patient id: p1, name: john smith
Observations:
- CategoryObservation[observationType: CategoryObservationType[code: t1, n
ame: stress level, categories: |low|medium|high|], value: medium]
Please press the ENTER key to continue:
=====================
Patient Record System
=====================
1. Add a measurement observation type
2. Add a category observation type
3. Add a patient
4. Add a measurement observation
5. Add a category observation
6. Display details of an observation type
7. Display a patient record by patient id
8. Save data
9. Load data
D. Display all data for inspection
X. Exit
Please enter an option (1-9 or D or X): x
Bye!
squaresolid
9