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

Using JAVA Write a program that manages a list of patients for a medical office.

ID: 3681699 • Letter: U

Question

Using JAVA

Write a program that manages a list of patients for a medical office. Patients should be represented as objects with the following data members: name (string) patient id # (string) address (string) height (integer; measured in inches) weight (double) date of birth (Date) date of initial visit (Date) date of last visit (Date) standard set of accessors get_age method: to compute and returns a patient's age in years (integer) get_time_as_patient method: to compute the number of years (integer) since the patient's initial visit. Note that this value can be 0. Get_time_since_last visit method: to compute the number of years (integer) since the patient's last visit. This value can be 0, too. The menu should look something like the following: Display list Add a new patient Show information for a patient Delete a patient Show average patient age Show information for the youngest patient Show notification list Quit

Explanation / Answer

########### Patient.java #########################

import java.util.Date;
import java.util.Calendar;

public class Patient {

   private String name;
   private String id;
   private String address;
   private int height;
   private double weight;
   private Date date_of_birth;
   private Date initialVisit;
   private Date lastVisit;
  
  
   public Patient(String name, String id, String address, int height,
           double weight, Date date_of_birth, Date initialVisit, Date lastVisit) {
       this.name = name;
       this.id = id;
       this.address = address;
       this.height = height;
       this.weight = weight;
       this.date_of_birth = date_of_birth;
       this.initialVisit = initialVisit;
       this.lastVisit = lastVisit;
   }


   public int get_age(){
       Calendar dob = Calendar.getInstance();
       dob.setTime(date_of_birth);
       Calendar today = Calendar.getInstance();
       int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
       if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR))
           age--;
       return age;
   }
  
   public int get_time_as_patient(){
       Calendar dob = Calendar.getInstance();
       dob.setTime(initialVisit);
       Calendar today = Calendar.getInstance();
       int interval = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
       if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR))
           interval--;
       return interval;
   }
  
   public int get_time_sice_last_visit(){
       Calendar dob = Calendar.getInstance();
       dob.setTime(lastVisit);
       Calendar today = Calendar.getInstance();
       int interval = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
       if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR))
           interval--;
       return interval;
   }
  
   @Override
   public String toString() {
       return "Name: "+name+", Id: "+id+", Address: "+address+", Height: "+height+", Weight: "+weight+", DOB: "+date_of_birth.toString()+
               ", Initial Visit: "+initialVisit.toString()+", Last Visit: "+lastVisit.toString();
   }
}

################### PatientManagement.java ####################################

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class PatientManagement {
   private static Scanner sc = new Scanner(System.in);
   private HashMap<String,Patient> patients = new HashMap<String, Patient>();
   ArrayList<String> notifications = new ArrayList<String>();
  
   public void displayList(){
       for(Map.Entry patient : patients.entrySet())
           System.out.println(patient.getValue().toString());
   }
  
   public void addPatient() throws ParseException{
       System.out.print("Enter Id: ");
       String id = sc.next();
       System.out.print("Enter name: ");
       String name = sc.nextLine();
       System.out.print("Enter address: ");
       String address = sc.nextLine();
       System.out.print("Enter height: ");
       int height = sc.nextInt();
       System.out.print("Enter weight: ");
       double weight = sc.nextDouble();
      
       SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
       System.out.print("Enter DOB(dd-mm-yyyy): ");
       Date dob = dateFormat.parse(sc.next());
       System.out.print("Enter Initial Visit date(dd-mm-yyyy): ");
       Date initialVisit = dateFormat.parse(sc.next());
       System.out.print("Enter Last Visit date(dd-mm-yyyy): ");
       Date lastVisit = dateFormat.parse(sc.next());
      
       Patient patient = new Patient(name, id, address, height, weight, dob, initialVisit, lastVisit);
      
       patients.put(id, patient);
      
   }
  
   public void showInfo(String id){
       if(patients.get(id)!=null)
           System.out.println(patients.get(id).toString());
       else
           System.out.println("Patient with id = "+id+" does not exist.");
   }
  
   public void delete(String id){
       if(patients.get(id)!=null)
           patients.remove(id);
       else
           System.out.println("Patient with id = "+id+" does not exist.");
   }
  
   public void averageAge(){
       if(patients.size() == 0){
           System.out.println("ANo patient exist");
           return;
       }
       int totaAage = 0;
           for(Map.Entry patient : patients.entrySet())
               totaAage = totaAage + ((Patient)patient.getValue()).get_age();
       System.out.println("Average age: "+(double)totaAage/patients.size());
   }
  
   public void youngestInfo(){
       if(patients.size() == 0){
           System.out.println("No patient exist");
           return;
       }
       int min = 0;
       String id = null;
       for(Map.Entry patient : patients.entrySet()){
           int age = ((Patient)patient.getValue()).get_age();
           if(min > age){
               min = age;
               id = (String)patient.getKey();
           }
       }
       System.out.println("YOungestt patient Info: "+patients.get(min).toString());
   }
  
   public void notificationList(){
       for(String s: notifications)
           System.out.println(s);
   }
  
   public static void main(String[] args) throws ParseException {
      
       PatientManagement mng = new PatientManagement();
       int op;
       String id;
       while(true){
           System.out.println("1. Display list");
           System.out.println("2. Add a new patient");
           System.out.println("3. Show information for a patient");
           System.out.println("4. Delete a patient");
           System.out.println("5. Show average patient age");
           System.out.println("6. Show information for the youngest patient");
           System.out.println("7. Show notification list");
           System.out.println("8. Quit");
          
           op = sc.nextInt();
          
           switch(op){
           case 1:
               mng.displayList();
               break;
          
           case 2:
               mng.addPatient();
               break;
           case 3:
               System.out.print("Enter Id of patient: ");
               id = sc.next();
               mng.showInfo(id);
               break;
           case 4:
               System.out.print("Enter Id of patient: ");
               id = sc.next();
               mng.delete(id);
               break;
           case 5:
               mng.averageAge();
               break;
           case 6:
               mng.youngestInfo();
               break;
           case 7:
               mng.notificationList();
               break;
           case 8:
               op = 8;
               break;
           }
          
           if(op==8)// exit
               break;
       }
   }
      
}

Please let me know in case of any doubt/issue.

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