Question: Phase 4: Interactions Next, implement the Interaction and InteractionList classes, and add additional methods to all of the other classes, to allow a complete search
Phase 4: Interactions
Next, implement the Interaction and InteractionList classes, and add additional methods to all of the other classes, to allow a complete search for dangerous medicine interactions.
The Interaction class is a very short class that will allow one single object to store information of the form chemical1 in medicine1 interacts with chemical2 in medicine2. This will permit such information to be sent as a single parameter to methods, or returned as the result of methods. This is a common use for classes and objects. The Interaction class should have:
Instance variables to hold 2 Medicines, and 2 Chemicals contained in them, which have a bad interaction. Make sure you can tell which medicine contains which chemical.
An instance method void setMeds(Medicine, Medicine) which will set the two Medicine fields, and an instance method void setChems(Chemical, Chemical) which will set the two Chemical fields. Make sure that the order is the same so that the first parameter to setChems corresponds to the first parameter to setMeds. It is being done this way because the medicines and chemicals will be found in very different places in your code.
A standard toString method which will produce a String in the format below, which can also be seen in the sample output.
MiracleCure contains eekamouse interacting with faroutman in Hydramax
The InteractionList class should be almost the same as the other two list classes, and should have:
Instance variables that will allow a list of up to 10 Interaction objects to be stored. Use a simple partially-full array to do this. You may assume that the list will never become full no error checking is needed.
A constructor with no parameters that creates an empty list.
An instance method void addInteraction (Interaction) which will add an interaction to the list.
A standard toString method which will return a multi-line String, with each line starting with a tab (\t) character. If the list is empty, the line should be "\tNo Interactions. ". Otherwise it should give one line per interaction in the list, in the format produced by toString. See the sample output below for an example.
Now complete the job by adding various search functions to the other five classes written in Phases 1 to 3.
Add an instance method boolean contains(Chemical) to the ChemicalList class which will determine whether or not that Chemical appears in the list. Look for that specific object. Do not look at the name of the Chemical.
Add an instance method boolean interactsWith(Chemical) to the Chemical class which will determine whether or not this chemical interacts with the one passed as the parameter.
Add an instance method Interaction anyInteraction(ChemicalList) to the ChemicalList class. This will look for any interaction between any chemical in this list with any chemical in the list passed as the parameter. If none are found, it should return null. If any are found, it should return an Interaction object with its two Chemical instance variables set appropriately. There may be multiple interactions between chemicals in the two lists, but you only need to find one of them.
Add an instance method Interaction interactsWith(Medicine) to the Medicine class. It should look for any interaction between this medicine and the medicine passed as a parameter. If it finds one, it should return an Interaction object with all four instance variables set properly. If none are found, it should return null.
Add an instance method InteractionList findInteractions() to the MedicineList class. It should look for any interactions between any two medicines in this list of medicines. Every pair of medicines that interact should appear in the list only once (dont report that A interacts with B and also B interacts with A thats redundant). It should always return an InteractionList, never null. If there are no interactions, the list will simply be an empty list.
Finally, add a class method void drugInteractionReport() to the Patient class. This should look at every patient stored in the system, and check the list of medications prescribed to that patient for possible interactions. It should print a report in the format shown below, using println statements.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
