Question: I just need help with part 3 in java (parts 1 and 2 are already functioning): Starter File: Drugs.java STEP #1: 40 pts Read foodDrug2Category.txt

I just need help with part 3 in java (parts 1 and 2 are already functioning):

Starter File: Drugs.java

STEP #1: 40 pts

Read foodDrug2Category.txt into a Map where the key is the category of drug such as THINNER, ANTI_INFLAM etc., and each key maps to a set of drug/food names that are of that type. Then print out the Map with nothing but space between words, and lines sorted vertically.

foodDrug2Category can be found at: http://people.cs.pitt.edu/~hoffmant/S17-401/XC4/foodDrug2Category.txt

output: ANTI_COAG asparagus broccoli cabbage endive soybeans ANTI_INFLAM aspirin ibuprofen motrin ED_MEDS cialis viagra STATINS crestor lipex lipitor zocor THINNERS coumadin plavix 

STEP #2: 40 pts

Read patient2FoodDrug into a Map where the key is the patient name and the value is the set of meds they are on and/or foods they eat. Print the map out just as in Phase #1 where the order of the lines is sorted and the list of mesd/foods is sorted.

patient2FoodDrug can be found at: http://people.cs.pitt.edu/~hoffmant/S17-401/XC4/patient2FoodDrug.txt

ouput: Bob_Jones asparagus lipitor Ed_Smith plavix viagra Jane_Doe lipitor plavix John_Doe aspirin broccoli plavix Tom_Smith cialis soybeans 

STEP#3: 20 pts.

Anyway you can using the dontMix file and the maps you have already generated, print the set of names of those people who are using food/drugs that should not be mixed.

dontMix can be found at: http://people.cs.pitt.edu/~hoffmant/S17-401/XC4/dontMix.txt output: Ed_Smith John_Doe 

Here is my code with function parts 1 and 2 ( I need help with part 3 ):

import java.util.*; import java.io.*;

public class Drugs { public static void main( String[] args ) throws Exception { BufferedReader foodDrug2CategoryFile = new BufferedReader( new FileReader( "foodDrug2Category.txt" ) ); BufferedReader patient2FoodDrugFile = new BufferedReader( new FileReader( "patient2FoodDrug.txt" ) ); BufferedReader dontMixFile = new BufferedReader( new FileReader( "dontMix.txt" ) ); TreeMap> foodDrug2Category = new TreeMap>(); TreeMap> patient2FoodDrug = new TreeMap>(); TreeSet drugs = new TreeSet(); TreeSet foods = new TreeSet(); while( foodDrug2CategoryFile.ready() ) { ArrayList tokens = new ArrayList( Arrays.asList( foodDrug2CategoryFile.readLine().split( "," ) ) ); String drugType = tokens.remove(0); foodDrug2Category.put( drugType, new TreeSet( tokens ) ); } //System.out.println( foodDrug2Category ); for (String drugType : foodDrug2Category.keySet() ) { drugs = foodDrug2Category.get( drugType ); System.out.print( drugType + "\t" ); for (String drug : drugs ) { System.out.print( drug + " " ); } System.out.println(); } System.out.println(); while( patient2FoodDrugFile.ready() ) { ArrayList tokens = new ArrayList( Arrays.asList( patient2FoodDrugFile.readLine().split( "," ) ) ); String name = tokens.remove(0); patient2FoodDrug.put( name, new TreeSet( tokens ) ); } for (String name : patient2FoodDrug.keySet() ) { foods = patient2FoodDrug.get( name ); System.out.print( name + "\t" ); for (String food : foods ) { System.out.print( food + " " ); } System.out.println(); } //System.out.println( patient2FoodDrug ); } // END MAIN

} // END CLASS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!