I asked this question here (thinking I would help people) Creating an unnecessary getter and unearthed a huge area of ignorance I have.
In this answer it was pointed out to me I had a fatal flaw in my code and I quote for ease:
"This is wrong:
public Patient(final String ptNo, final String ptName,
final String procDate, final int procType, final String injury,
final String drName) throws IOException
{
Patient.ptNo = getPtNo();
Patient.ptName = getPtName();
Patient.procDate = getProcDate();
Patient.procType = getProcType();
Patient.injury = getPtNotes();
Patient.drName = getDrName();
}
As you're completely ignoring all values passed in as parameters. Instead do:
public Patient(final String ptNo, final String ptName,
final String procDate, final int procType, final String injury,
final String drName) throws IOException
{
Patient.ptNo = ptNo;
Patient.ptName = ptName;
Patient.procDate = procDate;
Patient.procType = procType;
Patient.injury = injury;
Patient.drName = drName;
}
Where here you're setting your class's fields with the parameter values."
What I don't understand, is why the values are being ignored. I call separate methods for eg:
public static String getPtName()
{
System.out.print("Enter patient name: \n");
try
{
ptName = stdin.readLine();
} catch (IOException e)
{
System.out.println("Error! Enter a valid option.");
getPtName();
}
return ptName;
}
So I thought that was the same, in a longer way of writing the second block of code.
Can someone please explain to me, why it is different?
edit The assignment requirements from uni.
C) Provide a constructor for the class that accepts the patient number (a String), patient name (a String), procedure date (a String in the format dd/mm/yy), procedure type (an int), the injury description (a String) and the doctor name of the physician who is administering the patient’s treatment.
This constructor should initialise the instance variables with the corresponding parameter values that have been passed in - it should also initialise the patient notes instance variable to the injury description that was passed in initially and initialise the patient status instance variable to ‘S’ (indicating that the new patient has had a procedure Scheduled).
public Patient (String patientNo, String patientName, String procedureDate, int procedureType, String injuryDescription, String doctorName)
D) Implement accessors for the patient number, patient name, procedure date, patient notes and doctor name instance variables.