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

Write a program that manages a list of patients for a medical office. Patients s

ID: 3805503 • Letter: W

Question

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)

The data member “patient id #” is defined to be a

key

. That is, no two patients can have

the same patient id #. In addition to the standard set of accessors for the above data

members, define the fol

lowing methods for class Patient.

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 va

lue 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.

Your program will create a list of patient objects and provide the user with a menu of

choices for accessing

and manipulating the

data on that list. The list must be an object of

the class List that you will define.

Internally, the list object must maintain its list as a

singly linked list with two references, one for head and one for tail.

As usual, your Li

st

class will have the methods “

find,” “

size,” “contains

,” “remove,”

“add,”, “get,”

“getNext,”, “reset,” “toString

,”. At the start, your program should read in patient data

from a text file for an initial set of patients for the list. The name of this file

should be

included on the “command line” when the program is run.

(Don’t hard code

the file name)

Each data item for a patient will appear on a separate line in

the file.

Your program

should be menu-

driven, meaning that it will display a menu of options for the user. The

user will choose one of

these options, and your program will carry out the request. The

program will then display the same menu again and get another

choice from the user.

This interaction will go on until the user chooses QUIT, which should be the last of the

menu’s options. The

menu should look something like the following:

1.

Display list

2.

Add a new patient

3.

Show information for a patient

4.

Delete a patient

5.

Show average patient age

6.

Show information for the youngest patient

7.

Show notification l

ist

8.

Quit

Enter your choice:

Details of each option:

Option 1: Display (on the screen) the names and patient id #’s of all patients in

order starting from the first one. Display the

information for one patient per line;

something like: Susan

Smith, 017629

Option

2: Add a new patient to the

END

of the list.

All

information about the new

patient (including name, patient id #, etc.)

is to be requested (input) from the user

interactively. That is, you will need to ask for 14 pieces of data from the user.

You’ll, of course, need to create a new patient object to hold this data.

NOTE:

As mentioned above, the patient id # field is a

key

. So, if the user types in

a patient id # that happens to be the same as

an already existing patient’s, then

you should display an error message and cancel the operation. Therefore, it is

probably a

good idea to ask for the patient id # first and test it immediately (by

scanning the objects on the list).

Option

3: Display (in a neat format) all the information pertaining to the patien

t

whose patient id # is given by the user. Namely, display the following information:

o

name

o

patient id #

o

address

o

height (shown in feet and inches; for example, 5 ft, 10 in)

o

weight

o

age

o

number of years as a patient (display “less than one year” if 0)

o

number of years since last visit (display “less than one year” if 0)

o

Indication that patient is overdue for a visit

NOTE:

The last item is displayed only if it has been 3 or more years since

the patient’s last visit.

If the user inputs a patient id

# that does

not

exist, then the program should

display an error message and the operation should be canceled (with the menu

immediately being displayed again for another request).

Option

4: Delete the patient whose id # is given by the user. If the patient is not

on the

list, display an error message.

Option 5: Show the average age (to one decimal place) of the patients.

Option

6:

Display (in a neat format) all the information (same as operation 3)

about the youngest patient.

Option

7: Display the names (and patient id

#’s) of all patients who are overdue

for a visit. As noted above, “overdue” is

defined as 3 or more years since the last

visit.

Option 8: Quit the program.

NOTE:

When the user chooses to quit, you should ask if they would like to save

the patient information to a file. If so, then

you should prompt for the name of an

output (text) file, and then write the data pertaining to

all

patients to that file. The

output for each patient should be in the same format as in the input file. In this

way, your output fil

e can be used as input on

another run of your program. Make

certain to maintain the order of the patients in the output file as they appear on the

list. Be

careful not to overwrite your original input file (or any other file, for that

matter).

Note

:

Try to

implement the various menu options as separate methods (aside

from

“main”)

.

However:

DO NOT DEFINE such “option methods

” as part of the class

List.

Of course, the Java code that implements an option (whether it’s in the “main”

method or not) should def

initely use List’s methods

to help do its job.

Explanation / Answer

// Patients.java

// ====

import java.util.Scanner;
import java.util.Date;

public class Patient {
   private String name;
   private String patientId;
   private String address;
   private int height;
   private double weight;
   private Date dob;
   private Date init_visit;
   private Date last_visit;
   private static int id = 0;

   /** CONSTRUCTOR **/
   public Patient(
       String name, String address,
       int height, double weight,
       Date dob, Date init_visit,
       Date last_visit ) {
       this.name        = name;
       this.address    = address;
       this.height       = height;
       this.weight       = weight;
       this.dob        = dob;
       this.init_visit   = init_visit;
       this.last_visit   = last_visit;
       this.patientId = (String)++id;
   }

   /**
   * Get the age of a patient in years.
   *
   * returns {int}
   */
   public int getAge() {
       Date now = new Date();
       System.out.println(dob);
       return 0;
   }

   public int timeAsPatient() {

   }

   public int sinceLastVisit() {

   }
}

// PatientsDBDriver.java

// ====

import java.util.Scanner;
import java.io.PrintWriter;
import java.io.File;


public class PatientDBDriver {
   public static void main(String[] args) throws Exception {      

       PrintWriter fo    = new PrintWriter();
       Scanner in        = new Scanner(System.in);

       System.out.print("Enter the filename: ");
       String filename = in.next();
       File f            = new File(filename);
       Scanner reader = new Scanner(f);

       Patients[] patientsDB = loadFromFile(reader);      

       showMenu();
       int choice = in.nextInt();
       doChoice(choice);

       while (choice != 8) {

           showMenu();
           choice = in.nextInt();
           doChoice(choice);

       }
   }

   /**
   * Shows the menu to the user screen.
   */
   public static void showMenu() {      
       System.out.print("1. Display List 2. Add a new patient 3. Show information for a patient 4. Delete a patient 5. Show average patient age 6. Show information for the youngest patient 7. Show notification list 8. Quit ");
       System.out.print("Type or 8 to quit: ");
   }

   /**
   * Choice switch statement for doing what is necessary.
   *
   * @param    {int}    choice    Choice user has entered.
    */
   public static void doChoice(int choice) {
       switch (choice) {
           case 1:
               showList();
       }
   }

   /**
   * Creates a new Patient from the file.
   */
   public static Patient makePatient(Scanner reader) {
       String name        = reader.next();
       String address        = reader.nextLine();
       int height          = reader.nextInt();
       int weight            = reader.nextInt();
       String dob          = reader.next();
       String init_visit    = reader.next();
       String last_visit   = reader.next();
       String patientId    = reader.next();
       Patient p1            = new Patient(
                                   name, address,
                                   height, weight,
                                   dob, init_visit,
                                   last_visit, patientId);      
       return p1;
   }

   /**
   * Loads a patients as an array from the file.
   */
   public static Patients[] loadFromFile(Scanner reader) {
       Patients[] allPatients = new Patients[20];      
       while (reader.hasNextLine()) {
           makePatient(reader);
       }
   }

   public static void showList() {

   }
}

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