Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that we want to help physicians to diagnose illnesses. A physician obser

ID: 3716993 • Letter: S

Question

Suppose that we want to help physicians to diagnose illnesses. A physician observes a patient's symptoms and considers the illnesses that could be associated with those symptoms. Design and implement a class PhysiciansHelper that provide a list of those illnesses.
PhysiciansHelper should contain a dictionary of illnesses and symptoms. A method should read a text file of illnesses and their symptoms into the dictionary. See format in sample data file.
PhysiciansHelper should read a list of symptoms for a patient. A method should read a list of symptoms and store into a list. Then, it finds a list illnesses that are associated with those symptoms. See format in sample run output.
Note: I have modified specification and requirements of this project
Project requirements:
? You will need to complete two methods in PhysiciansHelper class:
public void processDatafile();
public void processSymptoms();
Refer to PhysiciansHelper for detailed info.
? You must use the predefined private Map<String, List<String>> symptomChecker to store symptoms to illnesses mapping info. See format in sample run output.
? All string data are not case sensitive, i.e. should work for either uppercase or lowercase letters.
? In processSymptoms() methods, you must
o list possible symptoms in sorted order.
o read user input symptoms in single line
o check for invalid symptoms and eliminate duplicated symptoms
o display result in format as shown in sample output (must count number of matched symptoms)
? Use Java API Map and List in your project
https://docs.oracle.com/javase/8/docs/api/java/util/Map.html
https://docs.oracle.com/javase/8/docs/api/java/util/List.html
Here are some methods that you may need:
Map: get(), put(), containsKey(), keySet(), entrySet()
List: add(), contains(), size()
Compile program: javac PhysiciansHelper.java
Sample Run: Note: I expect similar output from your program
$ cat sample_data.txt // contents of sample data file
cold: runny nose, cough, sore throat
flu: runny nose, cough, sore throat, muscle aches, fever
mumps: high fever, rash, swelling
whooping cough: cough, rash, high fever
acid reflux: chest pain, burping
chickenpox: fever, blister
measles : runny nose, cough, fever, rash
norovirus : nausea, diarrhea, vomiting
ague: sweatiness, achy, high fever
$ javac PhysiciansHelper.java
$ java PhysiciansHelper
Enter data filename: sample_data.txt
============================================
symptomChecker map: // display contents of map
achy=[ague]
blister=[chickenpox]
burping=[acid reflux]
chest pain=[acid reflux]
cough=[cold, flu, whooping cough, measles]
diarrhea=[norovirus]
fever=[flu, chickenpox, measles]
high fever=[mumps, whooping cough, ague]
muscle aches=[flu]
nausea=[norovirus]
rash=[mumps, whooping cough, measles]
runny nose=[cold, flu, measles]
sore throat=[cold, flu]
sweatiness=[ague]
swelling=[mumps]
vomiting=[norovirus]
============================================
The possible symptoms are: // display symptoms in sorted order
achy
blister
burping
chest pain
cough
diarrhea
fever
high fever
muscle aches
nausea
rash
runny nose
sore throat
sweatiness
swelling
vomiting
============================================
Enter symptoms: cough,rash,cough,fever,blisterx,cough,runny NOSE
=>duplicate symptom:cough
=>invalid symptom:blisterx
=>duplicate symptom:cough
============================================
PatientSymptoms list: [cough, rash, fever, runny nose]
Possible illnesses that match any symptom are:
==> Disease(s) match 1 symptom(s)
chickenpox
mumps
==> Disease(s) match 2 symptom(s)
whooping cough
cold
==> Disease(s) match 3 symptom(s)
flu
==> Disease(s) match 4 symptom(s)
measles

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

sample_data.txt

cold: runny nose, cough, sore throat
flu: runny nose, cough, sore throat, muscle aches, fever
mumps: high fever, rash, swelling
whooping cough: cough, rash, high fever
acid reflux: chest pain, burping
chickenpox: fever, blister
measles : runny nose, cough, fever, rash
norovirus : nausea, diarrhoea, vomiting
ague: sweatiness, achy, high fever

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

PhysiciansHelper.java

import java.util.*;

import java.io.*;

public class PhysiciansHelper

{

// symptom to illnesses map

private Map<String, List<String>> symptomChecker;

/* Constructor symptomChecker map using TreeMap */

public PhysiciansHelper()

{

// use TreeMap, i.e. sorted order keys

symptomChecker = new TreeMap<String,List<String>>();

} // end default constructor

/* Reads a text file of illnesses and their symptoms.

Each line in the file has the form

Illness: Symptom, Symptom, Symptom, ...  

Store data into symptomChecker map */

public void processDatafile()

{

// Step 1: read in a data filename from keybaord

// create a scanner for the file

// Step 2: process data lines in file scanner

// 2.1 for each line, split the line into a disease and symptoms

// make sure to trim() spaces and use toLowercase()

// 2.2 for symptoms, split into individual symptom

// create a scanner for symptoms

// useDelimeter(",") to split into individual symptoms

// make sure to trim() spaces and use toLowercase()

// for each symptom

// if it is already in the map, insert disease into related list

// if it is not already in the map, create a new list with the disease

// Step 3: display symptomChecker map

// implement here.....

} // end processDatafile

/* Read patient's symptoms in a line and adds them to the list.

Input format: Symptom, Symptom, Symptom,...

Shows diseases that match a given number of the symptoms. */

public void processSymptoms()

{

// Step 1: get all possible symptoms from assciatedIllnesses map

// and display them

// Step 2: process patient symptoms, add to patientSymptoms list

// read patient's symptoms in a line, separated by ','

// create a scanner for symptoms

// UseDelimeter(",") to split into individual symptoms

// make sure to trim() spaces and use toLowercase()

// display invalid/duplicate symptoms

// add valid symptoms to patientSymptoms list

// Step 3: display patientSymptoms list

// Step 4: process illnesses to frequency count

// create a map of disease name and frequency count

// for each symptom in patientSymptoms list

// get list of illnesses from symptomChecker map

// for each illness in the list

// if it is already in the map, increase counter by 1

// if it is not already in the map, create a new counter 1

// ** need to keep track of maximum counter numbers

// Step 5: display result

// for count i = 1 to maximum counter number

// display illness that has count i

// implement here.....

} // end processSymptoms

public static void main(String[] args)

{

PhysiciansHelper lookup = new PhysiciansHelper();

lookup.processDatafile();

lookup.processSymptoms();

} // end main

} // end PhysiciansHelper

Explanation / Answer

PhysicianHelper.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Collections;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Scanner;

import java.util.Set;

import java.util.TreeMap;

public class PhysiciansHelper

{

// symptom to illnesses map

private Map<String, List<String>> symptomChecker;

Scanner keyboard = new Scanner(System.in);

/* Constructor symptomChecker map using TreeMap */

public PhysiciansHelper()

{

// use TreeMap, i.e. sorted order keys

symptomChecker = new TreeMap<String, List<String>>();

} // end default constructor

/*

* Reads a text file of illnesses and their symptoms.

*

* Each line in the file has the form

*

* Illness: Symptom, Symptom, Symptom, ...

*

* Store data into symptomChecker map

*/

public void processDatafile()

{

// Step 1: read in a data filename from keybaord

System.out.println("Enter filename:");

String filename = keyboard.nextLine();

// create a scanner for the file

Scanner symtomsFile;

try {

symtomsFile = new Scanner(new File(filename));

// Step 2: process data lines in file scanner

while (symtomsFile.hasNextLine()) {

String line = symtomsFile.nextLine();

// 2.1 for each line, split the line into a disease and symptoms

String[] values = line.trim().toLowerCase().split(":");

String disease = values[0].trim();

ArrayList<String> symptoms = new ArrayList<String>();

// 2.2 for symptoms, split into individual symptom

// useDelimeter(",") to split into individual symptoms

// make sure to trim() spaces and use toLowercase() for each

// symptom

symptoms.addAll(Arrays.asList(values[1].trim().toLowerCase().split(",")));

// if it is already in the map, insert disease into related list

for (String symptom : symptoms) {

if (symptomChecker.containsKey(symptom.trim())) {

symptomChecker.get(symptom.trim()).add(disease);

} else {

// if it is not already in the map, create a new list

// with the disease

ArrayList<String> diseases = new ArrayList<String>();

diseases.add(disease);

symptomChecker.put(symptom.trim(), diseases);

}

}

}

} catch (FileNotFoundException e) {

e.printStackTrace();

}

// Step 3: display symptomChecker map

System.out.println("======================================================");

System.out.println("Contents of the Map: ");

for (Entry<String, List<String>> entry : symptomChecker.entrySet()) {

String key = entry.getKey().toString();

List<String> values = entry.getValue();

System.out.println(key + "=" + values);

}

} // end processDatafile

/*

* Read patient's symptoms in a line and adds them to the list.

*

* Input format: Symptom, Symptom, Symptom,...

*

* Shows diseases that match a given number of the symptoms.

*/

public void processSymptoms()

{

// Step 1: get all possible symptoms from assciatedIllnesses map and

// display them

System.out.println("======================================================");

System.out.println("The possible symptoms are:");

for (Entry<String, List<String>> entry : symptomChecker.entrySet()) {

String key = entry.getKey().toString();

System.out.println(key);

}

System.out.println("======================================================");

// Step 2: process patient symptoms, add to patientSymptoms list

System.out.println("Enter symptoms: ");

Set<String> possibleSymptoms = symptomChecker.keySet();

ArrayList<String> validSymptoms = new ArrayList<String>();

// read patient's symptoms in a line, separated by ','

// UseDelimeter(",") to split into individual symptoms

// make sure to trim() spaces and use toLowercase()

String[] symptomsEntered = keyboard.nextLine().trim().toLowerCase().split(",");

for (String symptom : symptomsEntered) {

// display invalid/duplicate symptoms

if (validSymptoms.contains(symptom)) {

System.out.println("=>duplicate " + symptom);

} else if (!possibleSymptoms.contains(symptom)) {

System.out.println("=>invalid " + symptom);

} else {

// add valid symptoms to patientSymptoms list

validSymptoms.add(symptom);

}

}

// Step 3: display patientSymptoms list

System.out.println("======================================================");

System.out.println("PatientSymptoms list: " + validSymptoms);

// Step 4: process illnesses to frequency count

System.out.println("Possible illnesses that match any symptom are:");

List<String> illnesses = new ArrayList<String>();

for (Entry<String, List<String>> entry : symptomChecker.entrySet()) {

String key = entry.getKey().toString();

List<String> values = entry.getValue();

for (String symptom : validSymptoms) {

if (key.equals(symptom)) {

illnesses.addAll(values);

}

}

}

// Step 4: process illnesses to frequency count

// create a map of disease name and frequency count

Map<Integer, String> illnessFreq =new TreeMap<Integer, String>();

for (String symptom : illnesses) {

int freq = Collections.frequency(illnesses, symptom);

illnessFreq.put(freq, symptom);

}

for (Entry<Integer, String> entry : illnessFreq.entrySet()) {

int key = entry.getKey();

String value = entry.getValue();

System.out.println("==> Disease(s) match "+key+" symptom(s)");

System.out.println(value);

}

keyboard.close();

} // end processSymptoms

public static void main(String[] args)

{

PhysiciansHelper lookup = new PhysiciansHelper();

lookup.processDatafile();

lookup.processSymptoms();

} // end main

} // end PhysiciansHelper

sample_data.txt

cold: runny nose, cough, sore throat
flu: runny nose, cough, sore throat, muscle aches, fever
mumps: high fever, rash, swelling
whooping cough: cough, rash, high fever
acid reflux: chest pain, burping
chickenpox: fever, blister
measles : runny nose, cough, fever, rash
norovirus : nausea, diarrhea, vomiting
ague: sweatiness, achy, high fever

Sample Output:

Enter filename:
D:workspaceTestsrcsample_data.txt
======================================================
Contents of the Map:
achy=[ague]
blister=[chickenpox]
burping=[acid reflux]
chest pain=[acid reflux]
cough=[cold, flu, whooping cough, measles]
diarrhea=[norovirus]
fever=[flu, chickenpox, measles]
high fever=[mumps, whooping cough, ague]
muscle aches=[flu]
nausea=[norovirus]
rash=[mumps, whooping cough, measles]
runny nose=[cold, flu, measles]
sore throat=[cold, flu]
sweatiness=[ague]
swelling=[mumps]
vomiting=[norovirus]
======================================================
The possible symptoms are:
achy
blister
burping
chest pain
cough
diarrhea
fever
high fever
muscle aches
nausea
rash
runny nose
sore throat
sweatiness
swelling
vomiting
======================================================
Enter symptoms:
cough,rash,cough,fever,blisterx,cough,runny NOSE
=>duplicate cough
=>invalid blisterx
=>duplicate cough
======================================================
PatientSymptoms list: [cough, rash, fever, runny nose]
Possible illnesses that match any symptom are:
==> Disease(s) match 1 symptom(s)
mumps
==> Disease(s) match 2 symptom(s)
cold
==> Disease(s) match 3 symptom(s)
flu
==> Disease(s) match 4 symptom(s)
measles

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote