Starting from:

$29.99

Assignment 2: Collections

Assignment2: Collections
Objectives
Upon completion of this assignment, you need to be able to: • Practice creating a class that implements an interface in Java. • Use the Node class to create a reference-based list. • Use Exception Handling techniques. • Read and understand specifications. • Implement testing of code during development. Introduction
Alocalpharmacywouldliketokeepasmalldatabaseofitsclientsandalistofthemedications that each patient is currently taking. For now, it is confined to local residents, but the pharmacy is hoping to tap into the larger region and include communication with the hospitals. We are tasked with supporting a basic system that will monitor medication lists to laterattachtopatientfiles.Sincemostpeoplearenottakinglargenumbersormedications, we decide to use the basic List ADT to manage each patient’s medication information. We haven’t decidedwhether to useanarray-basedlist orareference-based list,so we will implement both. That way we can plug in whichever one suits the client’s needs, without havingtoaltertheclient’shandlingofthelists.Thearray-basedmedicationlisthasalready been completed and tested. We need to complete the reference-based list. In this assignment you will: • Develop the MedListRefBased class that implements the standard List interface approved by the client. • Use the doubly-linked list as the primary data field in this class; it is described in the textbook’s Chapter 5, beginning on page 280.
QuickStart
(1) Create a fresh directory to contain this assignment: CSC115/assn2 is a recommended name. Download this pdf file and the .java files to this directory. (2) Download and extract the docs.zip and javafiles.zip in the same directory. A docs directorywillbecreatedtostorethespecificationsforthe public classes. The following links will work if the documents are stored in the docs directory local to this pdf file. • List specifications • MedListArrayBased specifications • Medication specifications (3) ExaminetheListspecificationdocument.ItissimilartotheADTdescriptioninthe textbook, page 204. The List.java file contains all the method headers required ofanyclassthatimplementsaList.Notethateachmethoddoesnotcontainabody; the implementation is never part of the ADT. Note also that the description uses Java generics, described in the textbook, page 291. This allows the developer of a List to decide the particular data type of the elements stored in the list. (4) Examine the completed source code for the MedListArrayBased class. Note that it implements List<Medication, and thereby is-a List. Note also that MedListArrayBased implements every method of the List interface. The main method is used as the test harness for MedListArrayBased and tests every method, including the private methods. Use this test harness as a model for the tests that you will create in MedListRefBased. (5) Examinethecompletedsourcecodefor MedListListTester.Thisisanexample ofanexternaltester.Itisthetesterthatisrunoncethecompletedclassisreadyfor its final assessment, before submitting it to the client. Note that it can only test the methods that are listed in the List interface. It tests the list for functionality from the perspective of a user, the pharmacy, in this case. (6) Compile all the given Java files. You can run MedListArrayBased to examine the internal tester results. You can also run the MedListTester to examine the external test results. (7) Your job is to create a class called MedListRefBased that implements List<Medication. It must contain all the required public methods and implement the list using a doubly-linked list, instead of an array. See Chapter 5 for information on the doubly-linked list.
(8) Once the code for MedListRefBased is completed and internal testing is done, you can make a very small change to the external tester and perform the external test on your code.
DetailedInstructions
There are several files supplied in this assignment. Examine them many times; their purpose makes sense as you work on the implementation of the linked list version of the medicationlist.Youonlyneedtocreateoneclass.Oncethatisdone,youwillneedtoalter the external tester class so that it calls the MedListRefBased constructor instead of the MedListArrayBased constructor. You are to create, implement and test the MedListRefBased class. Make sure of the following: (1) Themaindatastructureyouusetostorethemedicationsisadoubly-linkedlist,that youcreateyourself(noclassesthatextendthe java.util.List datastructureare to be used in your source code). (2) The class implements List<Medication. (3) Any private methods are properly commented (follow the MedListArrayBased source code as a guide). Note that comments are not required for any method that implements a method required by the List interface. Those methods are already commented and the methods you implement will follow those specifications. During the labs, you will be introduced to javadoc, a tool to create proper documentation. (4) The main methodinsideyoursourcecodetestseachofyourmethods.Createyour owninternaltesterfor MedListRefBased tothoroughlycheckthecodeyouwrite, including the private helper methods. You do not need to comment out the main method and you must not delete it. The marker will be looking for evidence of internal testing.
(5) Once you you are satisfied that all the internal testing works, then you can make a final check, using the external tester that is provided. If the external tester fails, then you must go back to the internal tester and take the necessary steps to debug and fix your code. The external tester will test your program when you alter the onelinein MedListTester.java thatdeclaresthe list variablebyinitializingit to a MedListRefBased object∗. You should see exactly the same output as when it tests the MedListarrayBased class.
Submission
Submit the following completed file to the Assignment folder on conneX. • MedListRefBased.java Please make sure you have submitted the required file(s) and conneX has sent you a confirmation email. Do not send [.class] (the byte code) files. Also, make sure you submit your assignment, not just save a draft. Draft copies are not available to the instructors, so they are not collected with the other submissions. We can find your draft submission, but only if we know that it’s there.

More products