In: Computer Science
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
public class MedicationEffects {
public static void main(String[] args) {
HashMap<String,
List<String>> list = new HashMap<>();
//storing medications and sides
effects in hashmap
list.put("Paremyd",
Arrays.asList(new String[] { "Agitation", "anxiety", "cold"
}));
list.put("Parlodel",Arrays.asList(new String[] { "Agitation",
"anxiety", "blue or pale skin" }));
Scanner sc = new
Scanner(System.in);
System.out.println("Enter name of
medication: ");
String name = sc.next();
if (list.get(name) != null)
System.out.println("Side Effects: "+list.get(name));
else
System.out.println("Medication not found");
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me