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

Write a java program in (intelliJ) For this project, you will build a hospital i

ID: 3844462 • Letter: W

Question

Write a java program in (intelliJ)

For this project, you will build a hospital interface, where you can:

- Login
- List patients
- Add patients
- See patient records
- Add/remove records for a patient.

You will be reading data from multiple files:
- employees.txt will be responsible for managing user login. (file will be provided)
- patients.txt will be responsible for managing the list of patients (file will be provided)
- Each patient will have their own file with their records.

Suggested way to tackle this homework:

- Start by downloading all the files.
- View the files to see all the formats.
- Read the employees from employees.txt
     o Create a new employee for each line.
     o Add the employees to the employees ArrayList of the hospital.
- Read the patients from patients.txt
     o Create a new patient for each line.
     o For each patient
      Read their designated records.
     • For each line, create a record and add it to the records ArrayList.
o Add the patient to the patients ArrayList of the hostpital.
- At this point, you have a hospital, with employees, patients.
- Write down the menu, with the appropriate switch / if/else statement.
- List_patients should be straightforward.
- View_records, you’ll need a way to find the patient from the patients array list
- Add_record should be straightforward.
- Remove_record, you’ll need a way to find the patient from the patients array list and then find the record from the records array list.
- Add_patient. You’ll need to add this user to the patients.txt and create a record file for them. Suppose you add Thomas, you will have to create a thomas.txt file to hold their records.
- Finally upon program exit (when the user enters 0), write back the data.
- Start with the patients, iterate over all the patients and write them down to patients.txt
     o For each patient, get the records and write it down to the appropriate file. Anne’s records go in to anne.txt, etc.

Sample run: Login: The users will be validated against employees.txt (file provided) Shivams-MacBook-Pro-2:examples shivamd$ java HospitalInterface SFSU Trauma Center at Holloway What is your username? shivam What is your password? password Incorrect username/password What is your username? shivam What is your password? securepassword Successfully logged in

Explanation / Answer

Hey!

As you given question have 6 subparts, I have done first 4 out of them.

Given below is the code for login, and first 3 options. The code is written in easy-to-read way and there should be no problems in understanding it. I have used some dummy text files for testing as you haven't provided any.

import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
import java.util.Date;


public class HospitalInterface{
public static void main(String[] args){
  
Scanner keyboard = new Scanner(System.in);
  
System.out.println(" SFSU Trauma Center at Hollowy ");

boolean loggedIn = false;

while(!loggedIn){
System.out.println("What is your username?");
String username = keyboard.nextLine();
System.out.println("What is your password?");
String password = keyboard.nextLine();

try {
File f = new File("employees.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String readLine = "";
while ((readLine = br.readLine()) != null) {
String[] loginData = readLine.split("-");
if(username.equals(loginData[0]) && password.equals(loginData[1])){
System.out.println(" Successfully logged in ");
loggedIn = true;
break;
}
}
}catch (IOException e) {
e.printStackTrace();
}
if(loggedIn){
break;
}else{
System.out.println(" Incorrect username/password ");
}
}
  
System.out.print("What would you like to do ");
System.out.print("Options ");
System.out.print("1. lists_patients ");
System.out.print("2. view_records ");
System.out.print("3. add_record ");
System.out.print("4. remove_record ");
System.out.print("5. add patient ");
System.out.println();

int choice = keyboard.nextInt();

List<String> patients = new ArrayList<>();
  
try {
File fd = new File("patients.txt");
BufferedReader brd = new BufferedReader(new FileReader(fd));
String readLine = "";
while ((readLine = brd.readLine()) != null) {
patients.add(readLine);
}
}catch (IOException e) {
e.printStackTrace();
}

switch(choice){
case 1:

for(int i = 0; i < patients.size(); i++){
System.out.println(patients.get(i));
}
break;
case 2:
  
boolean found = false;

while(!found){
System.out.println("Name of the patient you would like to view?");
String name = keyboard.next();
for (String string : patients) {
if(name.equals(string)){
try {
File f = new File(string.toLowerCase() + ".txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String readLine = "";
while ((readLine = br.readLine()) != null) {
String[] terms = readLine.split("-");
String[] x = terms[1].split(" ");
  
System.out.print(terms[0] + " - " + x[0] + " " + x[1]);
System.out.println();

}
}catch (IOException e) {
e.printStackTrace();
}
found = true;
}
}
if(found){
break;
}else{
System.out.println("Invalid Patient");
}   
}

break;
case 3:

boolean found1 = false;

while(!found1){
System.out.println("Name of the patient you would like to view?");
String name = keyboard.next();
for (String string : patients) {
if(name.equals(string.toLowerCase())){
System.out.println("What disease?");
String disease = keyboard.next();
try {
FileWriter fw = new FileWriter(string.toLowerCase() + ".txt", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw);
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date = new Date();

out.print(" " + disease + "-" + dateFormat.format(date));

out.close();
bw.close();
fw.close();
}catch (IOException e) {
e.printStackTrace();
}
found1 = true;
}
}
if(found1){
break;
}else{
System.out.println("Invalid Patient");
}   
}

break;
case 4:

break;
case 5:

break;
default:
}

}
}

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