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

3. Allow the user to enter a date. For now your user input will be three differe

ID: 3687077 • Letter: 3

Question

3. Allow the user to enter a date. For now your user input will be three different values since we haven't seen strings yet. Display whether the date was entered is valid or not. A valid month value must be from 1 to 12. A valid day is from 1 to valid value depending on the month. April, June, and November each have 30 days. February has 28 days (don't worry about leap years for now). The remaining months have 31 days. 4. Write a simple medical diagnosis tool. Of course this is not a real medical tool, it is just an example for our program. The possible scenarios and outcomes are: ispay whether the date was etered is said ala Do you have a fever? Do you have stuffy nose? Do you have a rash? Does your ear hurt? No symptoms then Hypochondia Stuffy nose only then Head Cold Fever and ear hurts only then Ear Infection Fever only then Flue Fever and rash only then Measles

Explanation / Answer

import java.util.*;
public class HelloWorld{
Scanner read=new Scanner(System.in);
public void medicalDiagnosis()
{
    char haveFever,haveNose,haveRash,haveEarHurt;
    System.out.println("Welcome to medical diagnosis tool");
    System.out.println("I'll ask you a few questions. Enter Y or N");
    System.out.print("Do you have fever: ");
    haveFever=read.next().charAt(0);
    System.out.print("Do you have running nose: ");
    haveNose=read.next().charAt(0);
    System.out.print("Do you have rashes: ");
    haveRash=read.next().charAt(0);
    System.out.print("Do you have ear hurt: ");
    haveEarHurt=read.next().charAt(0);
    if(Character.toUpperCase(haveFever)=='N' &&Character.toUpperCase(haveNose)=='N' && Character.toUpperCase(haveRash)=='N' && Character.toUpperCase(haveEarHurt)=='N')
    System.out.println("Sorry,you have hypochondia");
    else if(Character.toUpperCase(haveFever)=='Y' &&Character.toUpperCase(haveNose)=='N' && Character.toUpperCase(haveRash)=='N' && Character.toUpperCase(haveEarHurt)=='N')
    System.out.println("You have fever");
    else if(Character.toUpperCase(haveFever)=='Y' &&Character.toUpperCase(haveNose)=='N' && Character.toUpperCase(haveRash)=='Y' && Character.toUpperCase(haveEarHurt)=='N')
    System.out.println("You have measles");
    else if(Character.toUpperCase(haveFever)=='N' &&Character.toUpperCase(haveNose)=='Y' && Character.toUpperCase(haveRash)=='N' && Character.toUpperCase(haveEarHurt)=='N')
    System.out.println("You have cold and headache");
    else if(Character.toUpperCase(haveFever)=='Y' &&haveNose=='N' && haveRash=='N' && Character.toUpperCase(haveEarHurt)=='Y')
    System.out.println("You have fever and ear infection");
    else
    System.out.println("Sorry your diagnosis couldn't be completed");
}
public int findAbsolute()
{
    System.out.print(" Enter a value: ");
    int no=read.nextInt();
    return (no < 0) ? -no : no;
}
public void isValidDate()
{
    System.out.println("Lets validate a date");
    System.out.print("Enter day: ");
    int day=read.nextInt();
    System.out.print("Enter month: ");
    int month=read.nextInt();
    System.out.print("Enter year: ");
    int year=read.nextInt();
    if(year>0)
    {
        if(month<=12 && month>=1)
        {
            if(month==2)
            {
                if(day<=28 && day>=1)
                {
                    System.out.println("Valida date");
                }
                else
                {
                System.out.println("Invalid date specified. Invalid no of days provided");
                System.exit(0);
                }
            }
            else if(month==4 || month==6 || month==11)
            {
                if(day<=30 && day>=1)
                {
                    System.out.println("Valida date");
                }
                else
                {
                System.out.println("Invalid date specified. Invalid no of days provided");
                 System.exit(0);
                }
            }
            else
            {
                if(day<=31 && day>=1)
                {
                    System.out.println("Valida date");
                }
                else
                {
                    System.out.println("Invalid date specified. Invalid no of days provided");
                 System.exit(0);
                }
            }
        }
        else
        {
        System.out.println("Invalie data given. Invalid month specified");
         System.exit(0);
        }
    }
    else
    {
    System.out.println("Invalid date entered. Invalid year provided");
     System.exit(0);
    }
  
}
     public static void main(String []args){
         HelloWorld test=new HelloWorld();
       System.out.println("Absolute value "+test.findAbsolute());
       test.isValidDate();
       test.medicalDiagnosis();
     }
}

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