Question: import java.util.HashMap; import java.util.Scanner; / / Class to represent a Patient class Patient { private String cprNumber; / / CPR number of the patient private
import java.util.HashMap;
import java.util.Scanner;
Class to represent a Patient
class Patient
private String cprNumber; CPR number of the patient
private String caseHistory; Case history of the patient
private String nextAppointmentDate; Date of the next appointment
Constructor to initialize a Patient object
public PatientString cprNumber, String caseHistory, String nextAppointmentDate
this.cprNumber cprNumber;
this.caseHistory caseHistory;
this.nextAppointmentDate nextAppointmentDate;
Getter method to retrieve the CPR number
public String getCprNumber
return cprNumber;
Getter method to retrieve the case history
public String getCaseHistory
return caseHistory;
Getter method to retrieve the next appointment date
public String getNextAppointmentDate
return nextAppointmentDate;
Main class to implement the Dentist System
public class DentistSystem
HashMap to store patient records with CPR number as key
private static HashMap patientRecords new HashMap;
Main method
public static void mainString args
Scanner scanner new ScannerSystemin;
boolean isRunning true;
Main loop to display menu and handle user input
while isRunning
System.out.println Enter Patient Record";
System.out.println View Patient Record";
System.out.println Exit";
System.out.printEnter your choice: ;
int choice scanner.nextInt;
switch choice
case :
enterPatientRecordscanner;
break;
case :
viewPatientRecordscanner;
break;
case :
isRunning false; Exit the loop and terminate the program
break;
default:
System.out.printlnInvalid choice. Please enter again.";
scanner.close;
Method to enter a new patient record
private static void enterPatientRecordScanner scanner
System.out.printEnter patient's CPR number: ;
String cprNumber scanner.next;
System.out.printEnter patient's case history: ;
String caseHistory scanner.next;
System.out.printEnter patient's next appointment date: ;
String nextAppointmentDate scanner.next;
Create a new Patient object and add it to the HashMap
Patient patient new PatientcprNumber caseHistory, nextAppointmentDate;
patientRecords.putcprNumber patient;
System.out.printlnPatient record added successfully.";
Method to view an existing patient record
private static void viewPatientRecordScanner scanner
System.out.printEnter patient's CPR number: ;
String cprNumber scanner.next;
Check if the CPR number exists in the HashMap
if patientRecordscontainsKeycprNumber
If found, retrieve the patient record and display it
Patient patient patientRecords.getcprNumber;
System.out.printlnPatients Case History: patient.getCaseHistory;
System.out.printlnNext Appointment Date: patient.getNextAppointmentDate;
else
If not found, display a message
System.out.printlnPatient record not found.";
this is my code for patient records, and i want to test it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
