CMPT 270 Developing Object Oriented Systems Assignment 4

$35.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (6 votes)

Three Layer Architecture
Question 1 (6 points):
Purpose: Implementing Method Stubs
Degree of Diculty: Easy
Recall the HospitalSystem class from assignment 3. In this class, we used method stubs in place of task
5 (display the empty beds of the ward) and task 7 (release a patient). For this question, your job is to
implement these methods and provide a demonstration of them working.
Implement the displayEmptyBeds() and releasePatient() methods in the provided HospitalSystem class.
After these are implemented, run the main() method of the HospitalSystem class and invoke these methods. Copy-and-paste the console input/output into a le titled a4q1_demonstration.txt
Once everything is working, rename the class HospitalSystemA4Q1 before handing it in to moodle. This
renaming is strictly to help with marking. When using this class in subsequent questions you can return to
the original HospitalSystem name.
What to Hand In
• The completed HospitalSystemA4Q1.java program with task 5 and task 6 implemented.
• A document titled a4q1_demonstration.txt which shows the console input/ouput for task 5 and task
7.
Be sure to include your name, NSID, student number and course number at the top of all documents.
Evaluation
2 pts For correctly implementing task 5.
2 pts For correctly implementing task 7.
2 pts For a4q1_demonstration.txt.
Page 3
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
Question 2 (54 points):
Purpose: Practising refactoring using the HospitalSystem class.
Degree of Diculty: Moderate
The present version of the HospitalSystem class has a method to handle each of the tasks. In general,
each method does the following things:
• Obtains user input for the data needed for the task
• Checks the data for validity
• Invokes the methods from other classes to do the task
• Handles the result of the task
Any errors are handled by throwing an exception where the error is detected and catching it in the main
method of the HospitalSystem class to issue the error message.
For this question, your job is to refactor the task’s in the HospitalSystem class. Ideally, we would refactor
each task but for this assignment we will only refactor four tasks (details below). The remaining tasks can
be left where they are (with a few changes) or can be converted to classes, but all 8 tasks should work
correctly when invoking HospitalSystem.main().
(a) (20 points) Create the following new classes to refactor tasks 3, 4, 5 and 8 from the HospitalSystem
class:
• NewDoctor (task 3 from assignment 3)
• AssignDoctor (task 4 from assignment 3)
• EmptyBeds (task 5 from assignment 3)
• DropDoctor (task 8 from assignment 3)
These new classes should extend the provided CommandStatus class. The HospitalSystem class will
still obtain the data from the user and handle the result, but the new classes will do the rest of the task
(check the data for validity, and invoke methods in other classes to do the task).
Additional information on CommandStatus: Each of the above classes will extend this provided class.
Any errors that occur in the carrying out of a task should set the successful eld to false, and record an
appropriate error message in the errorMessage eld. The successful completion of a task should set
the successful eld to true. Also, if any information is to be returned to the invoking method, the usual
return of a function is not to be used. Instead, the information should be placed in appropriate elds
of the object for the task, and accessors provided for the client to obtain the information. This is done
so that it is possible to delay the invocation of a task and/or delay the accessing of the results of the
invocation. It also allows the task to be executed remotely, by sending the task to a remote location
and later receiving it back to retrieve the results. We will not use either of these properties, but they
are useful properties of tasks.
(b) (20 points) When the tasks are put into separate classes, most of these classes need to access the
Patient map, the Doctor map, and the Ward. In order to provide this access but prevent more than one
instance of any of these entities, you are to use the Singleton Pattern to implement them. Therefore
the following three singleton pattern classes must be created:
• PatientMapAccess
– dictionary: TreeMap
– DoctorMapAccess()
– dictionary(): TreeMap returns the dictionary containing all patients known
to the system
Page 4
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
• DoctorMapAccess
– dictionary: TreeMap
– DoctorMapAccess()
– dictionary(): TreeMap returns the dictionary containing all doctors known
to the system
• WardAccess
– ward: Ward
– WardAccess()
– initialize(name: String, minBedLabel: int, maxBedLabel: int) creates an instance of
a Ward for the hospital system. If the Ward has already been initialized this should throw and
error.
– ward(): Ward returns the ward known to the hospital system. If the Ward has not been initialized
this should throw an error.
The dictionaries required for PatientMapAccess and DoctorMapAccess should initially be empty. The
classes that need these data structures should now use static methods to access the them.
(c) (14 points) You will need to include internal documentation for all of the new classes. Proper internal
documentation includes:
• A comment just before the class header that gives an overview of the class. For example, if the
class models an entity, the comment might state what entity the class models and specify the key
features. Alternatively, if the class serves as a container, state what type of items the container
stores, and how these items are accessed. If the class is an interface, state what it provides an
interface for and whether there is anything special about the interface. Finally, if it has a control
function, what is it doing and controlling? Recall that comments for a class appear before the class
and begin with /**.
• A comment just before each instance variable stating what is stored in the eld, again beginning
with /**
• A comment before each constructor and method stating what it does. Note that the comment only
gives what the routine does, not how it does it. If it isn?t obvious from the code how it accomplishes
its goal, comments on how it is done belong in the body of the method.
• Single line comments as needed to improve the readability of your code. Over-use of single-line
comments will result in a deduction of marks.
• Use descriptive variable names and method names.
• Include good use of white space, especially reasonable indentation to improve the readability of
your code.
• When testing, hard-code all of the data. Minimize console input and output by only reporting
errors(These are the same principles we applied in CMPT 145).
What to Hand In
• A le titled A4Q2.jar of your complete system.
• A zip folder titled A4Q2.zip that contains:
– HospitalSystem.java
– NewDoctor.java
– AssignDoctor.java
– EmptyBeds.java
Page 5
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
– DropDoctor.java
– PatientMapAccess.java
– DoctorMapAccess.java
– WardAccess.java
Be sure to include your name, NSID, student number and course number at the top of all documents.
Evaluation
20 pts For the command classes (5 pts per class)
20 pts For the singleton classes (2 pts per required attributed/method)
14 pts For internal documentation of new classes (2 pts per class)
Page 6
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
Question 3 (25 points):
Purpose: Practising User Input/Output with Dialog Boxes
Degree of Diculty: Moderate
The second part of the assignment is to change the input and output (I/O) so that the user has the choice of
doing I/O via the console or by dialog boxes. A new instance variable should be added to the HospitalSystem
class called ioInterface that has type InputOutputInterface.
(a) (21 points) At the start of the project, a dialog box should be used to query the user as to which type
of I/O is to be used. Based on the selection, this new instance variable will either be initialized with
a ConsoleIO object or DialogIO object (both described below) which will allow the requested type of
I/O to be used. Recall, a variable can be declared as an interface type. But it must be initialized to an
object that implements that interface before it is used. Doing this allows us to utilize polymorphism
to achieve a dierent behaviour throughout our system. This part of the assignment should NOT be
implemented by having two versions of the methods of HospitalSystem. Instead, you are given an
interface, InputOutputInterface, with the operations needed for I/O. This interface will have two implementations:
• ConsoleIO which uses console input and output to implement the methods.
• DialogIO which uses dialog boxes to implement the methods. This class can extend the provided
AbstractDialogIO class which has the readChoice method implemented for you.
(b) (4 points) You will need to include internal documentation for all of the new classes. Proper internal
documentation includes:
• A comment just before the class header that gives an overview of the class. For example, if the
class models an entity, the comment might state what entity the class models and specify the key
features. Alternatively, if the class serves as a container, state what type of items the container
stores, and how these items are accessed. If the class is an interface, state what it provides an
interface for and whether there is anything special about the interface. Finally, if it has a control
function, what is it doing and controlling? Recall that comments for a class appear before the class
and begin with /**.
• A comment just before each instance variable stating what is stored in the eld, again beginning
with /**
• A comment before each constructor and method stating what it does. Note that the comment only
gives what the routine does, not how it does it. If it isn?t obvious from the code how it accomplishes
its goal, comments on how it is done belong in the body of the method.
• Single line comments as needed to improve the readability of your code. Over-use of single-line
comments will result in a deduction of marks.
• Use descriptive variable names and method names.
• Include good use of white space, especially reasonable indentation to improve the readability of
your code.
• When testing, hard-code all of the data. Minimize console input and output by only reporting
errors(These are the same principles we applied in CMPT 145).
What to Hand In
• A le titled A4Q3.jar of your complete system.
• A zip folder titled A4Q3.zip that contains:
– HospitalSystem.java
– ConsoleIO.java
Page 7
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
– DialogIO.java
Be sure to include your name, NSID, student number and course number at the top of all documents.
Evaluation
5 pts For correctly modifying the HospitalSystem class to allow for user selected I/O
8 pts For correctly implementing the ConsoleIO class (2 pts per method)
8 pts For correctly implementing the DialogIO class (2 pts per method)
4 pts For internal documentation of new classes (2 pts per class)
Page 8
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
Question 4 (10 points):
Purpose: Practising External Documentation
Degree of Diculty: Easy
Once you have completed the questions above, create a le called A4_documentation.pdf that includes
all the internal documentation for the refactored system. External documentation should include:
• A description of how to run your system. What class should be invoked, what method?
• Now that we have the beginning of a complete java application, you should include a demonstration
of your system running. This can be achieved by copy-and-pasting (or screen-grabbing) your console
input/output that shows you invoking each task.
• The status of your assignment. What is working and what is not working? What is tested and what
is not tested? If it is only partially working, the previous point should have described how to run that
part or parts that work. For the part or parts not working, describe how close they are to working. For
example, some of the alternatives for how close to working are (i) nothing done; (ii) designed but no
code; (iii) designed and part of the code; (iv) designed and all the code but anticipate many faults; or
(v) designed and all the code but with a few faults; (vi) working perfectly and thoroughly tested.
• Maintenance manual. This is information for the person or persons who must keep your system running, x any faults, and do any upgrades. The reader of the maintenance manual is expected to have
the same background and experience as yourself, but of course not having developed your system.
This part of the documentation will vary from assignment to assignment. For this assignment, it is
sucient to include a UML class diagram showing all the features of each class, and the relationships
(inheritance, uses and aggregation) amongst the classes (if any).
• UML diagrams should be generated with a program like UMLet or an online tool, such as https://
www.gliffy.com/uses/uml-software/ or https://www.draw.io/. Make sure that you use the correct
arrows and arrowheads. Incorrect arrowheads will lose several marks. You can also draw out a UML
diagram by hand and scan it. Just make sure it is easily readable.
What to Hand In
• A le titled A4_documentation.pdf
Be sure to include your name, NSID, student number and course number at the top of all documents.
Evaluation
10 pts For including all the required external documentation.
Page 9
Department of Computer Science
176 Thorvaldson Building
110 Science Place, Saskatoon, SK, S7N 5C9, Canada
Telephine: (306) 966-4886, Facimile: (306) 966-4884
CMPT 270
Developing Object Oriented Systems
Additional information
Commenting and Exceptions: When writing these classes, be sure to properly document each method,
including @param and @return comments. Also, if a method has a precondition, specify the precondition in
a @precond comment, and throw a runtime exception if it is not satised. Be sure to include a meaningful
error message in the String parameter for the exception constructor.
Levels of Protection: In keeping with the principle of information hiding, the instance variables of a class
should be private unless there is a very good reason to make them visible. Methods should be public
unless there is a very good reason to hide them.
Page 10