Hey guys,
I started a Java course just a few days ago and I'm not getting far since I've got a bit of a trouble wit hthe type Date.
My current task is to do this:
Add a Patient class to your project which stores the following information about a patient: the patient's reference number, the patient's name, the GP's (family doctor) name and the patient's date of birth as a Date. In addition, the class also stores the patient's arrival time and the time they started their treatment, both of type Time.
Write a constructor which sets the patient's reference number, name, GP's name and date of birth from suitable formal parameters. The date of birth should be represented by three formal parameters of type int which are then passed on as actual parameters to a Date constructor. The time when the patient arrived and the time when they start their treatment should be set to null.
Now, the problem is that I can the Patient class to assign all the needed values inside itself, but I can't seem to be able to make it pass it onto Date. Also, I'm doing this in BlueJ since I'm not ready for a real IDE yet.
At the moment I am only concerned with geting the type Date to work, and perhaps one that is done I'll be able to figre the rest myself. I'm pretty sure that the solution is really simple but I'm very new to this and I'm really confused now.
Can anyone give me a hin or point me in the right direction, or perhaps tell me what I'm doing wrong? Any help at all is greatle appreciated.
(Also it was said that I should have to make any changes to the Date class, which is one of the reasons why I am so confused).
/** public class Patient { // private int patientRefNumber; private String patientName; private String gpName; public static int d; public static int m; public static int y; public static int arrivalTime; public static int treatmentTime; /** * Creates object Patient. * @param refNumber - sets patient's reference number. * @param pName - sets patient's name. * @param gName - sets GP's name. * */ public Patient(int refNumber, String pName, String gName, int dayOfBirth, int monthOfBirth, int yearOfBirth) { patientRefNumber = refNumber; patientName = pName; gpName = gName; d = dayOfBirth; m = monthOfBirth; y = yearOfBirth; } /** * Stores date of birth of the patient into Date. */ public static void passToDate(int d, int m, int y) { Date day = new Date (d, m, y); } }
/** public class Date { /** Fields of a Date - just the day, month and year*/ private int day; private int month; private int year; /** * Constructor for objects of class Date * @param d - the day part of the date (1 - 31, depending on the month). * @param m - the month part of the date (1 - 12). * @param y - the year part of the date. */ public Date(int d, int m, int y) { day = d; month = m; year = y; } /** * @return the date as a String, format "09/11/2002" */ public String getAsString () { return as2Digits(day) + "/" + as2Digits(month) + "/" + year; } /** Internal method to add a leading zero if necessary. */ private String as2Digits (int i) { if (i <10) { return "0" + i; } else { return "" + i; } } }