I need to solve this :
You need to create, use and print a custom exception called DuplicatePateientIdException that
should be thrown when the admin tries to add a new patient using existing patient ID. The message
of the exception should be read as “Invalid patient ID. This patient ID is already used”
and Patient class like this :
import java.util.ArrayList;
import java.util.List;
// Defines class Patients
class Patient {
// Instance variables to store patient information
private int patientID;
private String patientName;
private String patientAddress;
private String patientMobileNumber;
private String patientEmail;
private char type;
ArrayList<Service> services;
// Default constructor to assign default value to instance variable
public Patient() {
patientID = 0;
patientName = patientAddress = patientMobileNumber = patientEmail = "";
type = ' ';
services = new ArrayList<Service>();
}
// Parameterized constructor to assign parameter values to instance variables
public Patient(int pID, String pn, String pa, String pm, String pe, char ty, ArrayList<Service> ser) {
patientID = pID;
patientName = pn;
patientAddress = pa;
patientMobileNumber = pm;
patientEmail = pe;
type = ty;
services = new ArrayList<Service>();
services = ser;
}
// Getter method to return patient id
public int getPatientID()
{
return patientID;
}
// Getter method to return patient name
public String getPatientName()
{
return patientName;
}
// Getter method to return patient address
public String getPatientAddress()
{
return patientAddress;
}
// Getter method to return patient mobile number
public String getPatientMobileNumber()
{
return patientMobileNumber;
}
// Getter method to return patient email
public String getPatientEmail()
{
return patientEmail;
}
// Getter method to return patient type
public char getType()
{
return type;
}
// Getter method to return patient services
public ArrayList<Service> getServices()
{
return services;
}
// Setter method to change patient id
public void setPatientID(int pID)
{
patientID = pID;
}
// Setter method to change patient name
public void setPatientName(String pn)
{
patientName = pn;
}
// Setter method to change patient address
public void setPatientAddress(String pa)
{
patientAddress = pa;
}
// Setter method to change patient mobile number
public void setPatientMobileNumber(String pm)
{
patientMobileNumber = pm;
}
// Setter method to change patient email
public void setPatientEmail(String pe)
{
patientEmail = pe;
}
// Setter method to change patient type
public void setType(char ty)
{
type = ty;
}
// Setter method to change patient services
public void setServices(ArrayList<Service> ser)
{
services = ser;
}
// Overrides method toString() to return service information
public String toString()
{
String result = "";
result += "\n Patient ID: " + patientID + "\n Patient Name: " + patientName +
"\n Patient Address: " + patientAddress +
"\n Patient Mobile Number: " + patientMobileNumber +
"\n Patient Email Address: " + patientEmail +
"\n Patient Type: " + type + "\n\n **** Service Availed **** ";
// Loops number of services availed
for(int c = 0; c < services.size(); c++)
result += services.get(c).toString() + "\n";
return result;
}
}// End of class Patients
i need to add this step in above code :
You need to create, use and print a custom exception called DuplicatePateientIdException that
should be thrown when the admin tries to add a new patient using existing patient ID. The message
of the exception should be read as “Invalid patient ID. This patient ID is already used”
NAD M.
It appears to me that there is a error here ? if (PatientIndexerFindIndexAt( newPatientID)>=0) { throw ( new DuplicatePatientException("duplicate patient exception")); } if (PatientIndexerFindIndexAt( newPatientID)>=0) { How can I solve it? Can you help me?11/25/20