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

For this homework, you will develop a very simple Medical Diagnosis System to ai

ID: 3721971 • Letter: F

Question

For this homework, you will develop a very simple Medical Diagnosis System to aid a clinic in determining whether a patient is healthy or suffering from a cold, the flu, the measles, the mumps, or if the diagnosis is uncertain. You will base your diagnosis on the chart below. Combinations of symptoms that do not fit any of the categories shown below will result in a diagnosis of “Uncertain.” Patients with a diagnosis of Measles, Mumps, or Uncertain will be asked to reschedule a follow-up appointment in 3 days.



For this project, you will write a program named DiagnosisSystem.java It must display a header that lists the name of the application – you may name it as you like – and provides instructions about using the program. For example,

The user should be prompted for the following input values:

Patient (name) - Input as a String.

Month - Input as an integer.

Day - Input as an integer.

Temperature - Input as a double.

Congestion (y/n) - Input that starts with y or Y should be considered as yes, any other input should be considered as no.

Aches (y/n) - Input that starts with y or Y should be considered as yes, any other input should be considered as no.

Rash (y/n) - Input that starts with y or Y should be considered as yes, any other input should be considered as no.

Swelling (y/n) - Input that starts with y or Y should be considered as yes, any other input should be considered as no.

You may assume the month and day occur during the year 2018.

The program should then output the patient’s name, the date (with 2018 as the year), the diagnosis, and the reschedule date (3 days after the date if the diagnosis is Measles, Mumps, or Uncertain, None otherwise – assume the clinic is open 7 days a week) as shown below.

Here are some examples:

Input/Error Handling

If the user enters an invalid date, the program should print an error message as soon as the error occurs and quit.
HINT: The statement System.exit(1); will cause the program to quit with a status of 1 indicating an error condition.
NOTE: You do not need to handle the situation where the user enters something other than an integer for the month or day, or something other than a double for temperature. We will learn to handle this later in the semester.

Here are some examples of handling invalid input:

The program must contain and use the completed version of the methods below. You are free to (and encouraged to) define and use additional methods, if you like – be sure to provide Javadoc for them.


Please note that your program should NEVER call the getReturnDate() method with illegal arguments because you should do thorough error checking BEFORE calling the method! This requirement is simply to give you practice in checking method parameters and throwing exceptions. It is good practice to include a helpful/descriptive message when you throw an exception. For this project, it is required that you include the message “Invalid date” with each IllegalArgumentException you throw.

Diagnosis Body Temperature Congestion Aches Rash Swelling Healthy less than 99 no no no no Cold less than 100 yes no no no Flu 100 or greater no yes no no Measles 100 or greater no no yes no Mumps 100 or greater no yes no yes

Explanation / Answer

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public class DiagnosisSystem {

   public static void main(String[] args) {
       DiagnosisSystem diagnosisSystem=new DiagnosisSystem();
       //Print Welcome message
       System.out.println("Welcome to the Diagnosis Decision Support System");
      
       //Read inputs
       Scanner sc=new Scanner(System.in);
       System.out.println("Patient:");
       String patientName=sc.nextLine();
       System.out.println("Month Day (e.g., 3 14):");
      
       String dayMonth=sc.nextLine();
       String arr[]=dayMonth.split(" ");
       int month=Integer.parseInt(arr[0]);
       int day=Integer.parseInt(arr[1]);
      
       //Check for Valid date
      
       isValidDate(month, day);
      
       System.out.println("Temperature:");
       double temperature=sc.nextDouble();
       sc.nextLine();
       System.out.println("Congestion (y,n):");
       String con=sc.nextLine();
       boolean congestion=false;
       if(con.equalsIgnoreCase("y"))
       {
           congestion=true;
       }
      
       System.out.println("Aches (y,n):");
       String ach=sc.nextLine();
       boolean aches=false;
       if(ach.equalsIgnoreCase("y"))
       {
           aches=true;
       }
      
       System.out.println("Rash (y,n): ");
       String ra=sc.nextLine();
       boolean rash=false;
       if(ra.equalsIgnoreCase("y"))
       {
           rash=true;
       }
      
       System.out.println("Swelling (y,n): ");
       String sw=sc.nextLine();
       boolean swelling=false;
       if(sw.equalsIgnoreCase("y"))
       {
           swelling=true;
       }
      
      
       String diagnosis=getDiagnosis(temperature, congestion, aches, rash, swelling);
      
       //Print the details
       System.out.println("Patient: "+patientName);
       //getReturnDate can be reused for date calculation as well
       System.out.println("Date : "+getReturnDate(month, day));
       System.out.println("Diagnosis:"+diagnosis);
       System.out.println("Return Date:"+getRescheduleDate(month, day, diagnosis));
      
   }

   //Return true if the date is a valid date during 2018
   //Return false otherwise
   public static boolean isValidDate(int month, int day) {
       if(month<0 || month>12 ||day<0 ||day>31)
       {
           return false;
       }
       //When day is more than 28 in feb
       if(month==2 &&day>28)
       {
           return false;
       }
       return true;
   }

  

   //Determine and return the diagnosis (Healthy, Cold, Flu, Measles, Mumps, Uncertain)
   //based on a patient's symptoms and the chart given above
   public static String getDiagnosis(double temperature, boolean congestion,
                                      boolean aches, boolean rash, boolean swelling) {
      
       if(!congestion&&!aches&&!rash&&!swelling &&temperature<99)
       {
           return "Healthy";
       }
       else if(congestion&&!aches&&!rash&&!swelling &&temperature<100)
       {
           return "Cold";
       }
       else if(!congestion&&aches&&!rash&&!swelling &&temperature>=100)
       {
           return "Flu";
       }
       else if(!congestion&&!aches&&rash&&!swelling &&temperature>=100)
       {
           return "Measles";
       }
       else if(!congestion&&aches&&!rash&&swelling &&temperature>=100)
       {
           return "Mumps";
       }
       return "Healthy";
                               
   }

  

   //Throw an IllegalArgumentException with the message, "Invalid date", if the
   //month and day do not represent a valid date in 2018
   //Return a date formatted as month/day/year, e.g., 12/9/2018, that occurs
   //3 days after the given month and day in 2018
   public static String getReturnDate(int month, int day) {
       if(month<0 || month>12 ||day<0 ||day>31)
       {
           return "Invalid Date";
       }
       //When day is more than 28 in feb
       if(month==2 &&day>28)
       {
           return "Invalid Date";
       }
       return month+"/"+day+"/2018";
                               
   }
public static String getRescheduleDate(int month,int day,String diagnosis)
{
   if(diagnosis!=null && diagnosis.equalsIgnoreCase("Measles")||diagnosis.equalsIgnoreCase("Mumps")||diagnosis.equalsIgnoreCase("Uncertain"))
   {
       SimpleDateFormat sdf = new SimpleDateFormat("mm/DD/yyyy");
       Calendar cal = Calendar.getInstance();  
       cal.set(Calendar.DAY_OF_MONTH, day);
       cal.set(Calendar.MONTH,month);
       cal.set(Calendar.YEAR, 2018);
       cal.add(Calendar.DAY_OF_MONTH, 3);
       return sdf.format(cal.getTime());
   }
   else
   {
       return "None";
   }
}


}

output:

Welcome to the Diagnosis Decision Support System
Patient:
Waseem
Month Day (e.g., 3 14):
3 14
Temperature:
99
Congestion (y,n):
n
Aches (y,n):
n
Rash (y,n):
n
Swelling (y,n):
y
Patient: Waseem
Date : 3/14/2018
Diagnosis:Healthy
Return Date:None

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