vendredi 6 mars 2015

Diagnosis System Program: walk thru



public class DiagnosisSystem {
public static final int JANUARY = 1;
public static final int FEBRUARY = 2;
public static final int NOVEMBER = 11;
public static final int DECEMBER = 12;
public static final int DAYS_PER_YEAR = 365;
public static final int[] DAYS_PER_MONTH = {0,
// 1, 2 , 3 , 4, 5 , 6, 7 , 8 , 9 , 10, 11, 12
31, 28, 31, 30, 31, 30, 31, 31, 30, 30, 30, 31,
};
/**
*Runs programs to return patient's results
*@param args command line argument
*@returns reults of test
*/
public static void main(String [] args) {
Scanner console = new Scanner(System.in);
System.out.println(" Welcome to the Diagnosis Decision Support System");
System.out.println("When prompted, please enter today's month and day (e.g., 3 14),");
System.out.println("the patient's full name, temperature, and whether the patient");
System.out.println("is experiencing congestion, aches, and/or a rash. A diagnosis");
System.out.println("of Healthy, Cold, Flu, Measles, or Uncertain will be output as");
System.out.println("well as a return date, if the diagnosis is Measles or Uncertain.");
String patient;
int month = 0;
int day = 0;
double temperature = 0;
String congestion;
String aches;
String rash;
System.out.println("Patient: ");
patient = console.nextLine();
System.out.println("Month Day (e.g., 3 14): ");
month = console.nextInt();
day = console.nextInt();
System.out.println("Temperature: ");
temperature = console.nextDouble();
System.out.println("Congestion (y,n): ");
congestion = console.next();
boolean c = false;
if (congestion.equals("y")) {
c = true;
}
System.out.println("Aches (y,n): ");
aches = console.next();
boolean a = false;
if (aches.equals("y")) {
a = true;
}
System.out.println("Rash (y,n): ");
rash = console.next();
boolean r = false;
if (rash.equals("y")) {
r = true;
}
String d = getDiagnosis(temperature, c , a, r);
System.out.println("Patient: " + patient);
System.out.println("Temperature: " + temperature);
System.out.println("Diagnosis: " + d);
isValidDate(month, day);
if (isValidDate(month, day)) {
String b = getReturnDate(month, day);
System.out.println("Return date: " + b );
} else {
System.out.println("Return date: ");
}
}

/**
*Validates the date entered
*@param month int
*@param day int
*@return true if valid month or day, false if invalid month or day
*/
//Return true if the date is a valid date during 2015
//Return false otherwise
public static boolean isValidDate( int month, int day) {
boolean validDate;
if ((month >= 1 || month <= 12) && (day >= 1 || day <= 31)) {
validDate = true;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) && (day <= 30)) {
validDate = true;
}
if((month == 1 || month == 2 || month ==3 || month ==5 || month == 7 || month == 8 || month == 10 || month == 12) && (day <= 31)) {
validDate = true;
}
if ((month == 2) && (day < 28)) {
validDate = true;
} else {
return false;
}return false;
}
/**
*
*
*/
//Determine and return the diagnosis (Healthy, Cold, Flu, Measles, Uncertain)
//based on a patient's symptoms and the chart given above.
public static String getDiagnosis(double temperature, boolean congestion, boolean aches, boolean rash) {
if (temperature < 99) {
if(!congestion && !aches && !rash)
System.out.println("Healthy");
} else if (temperature < 100) {
if (congestion && !aches && !rash)
System.out.println("Cold");
}
if (temperature >= 100) {
if(!congestion && aches && !rash)
System.out.println("Flu");
}
if ( temperature >= 100) {
if(!congestion && !aches && rash)
System.out.println("Measles");
} else {
System.out.println("Uncertain");
} return "Uncertain";
}
/**
*Throw an IllegalArgumentException if the month and day is not a valid
*date in 2015
*Return a date formatted as month/day/year, e.g., 12/9/2015, that occurs
*3 days after the given month and day in 2015
*@param month int months in 2015
*@param day int days in 2015
*@param year int year of 2015
*/
public static String getReturnDate(int month, int day) throws IllegalArgumentException {
int year = 2015;
String s4 = (month + "/" + day + "/" + year);
if ((month < 1 || month > 12) && (day < 1 || day > 31)) {
throw new IllegalArgumentException("Invalid response");
}
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
day = day + 3;
if (day > days[month]) {
month++;
}
if (day > days[year]) {
year++;
} return s4;
}


}





Aucun commentaire:

Enregistrer un commentaire