Question: I need help making my code work properly! Here is what I have: // Date Class class Date { private int month; private int day;

I need help making my code work properly!

Here is what I have:

// Date Class

class Date {

private int month;

private int day;

private int year;

public boolean isLeapYear(int yy)

{

if(yy%4==0 && yy%100==0 && yy%400==0)

return true;

return false;

}

public Date() throws Exception

{

try{

throw new Exception("Invalid Date Format");

}

catch(Exception e)

{

System.out.println(e.getMessage());

this.month=this.day=this.year=0;

}

}

public Date(String aDate)

{

try{

if(aDate.length()!= 10 || aDate.charAt(2)!='/' || aDate.charAt(5)!='/')

throw new Exception("Invalid Date Format");

int mm,dd,yy;

mm=Integer.parseInt(aDate.substring(0, 2));

dd=Integer.parseInt(aDate.substring(3,5));

yy=Integer.parseInt(aDate.substring(6));

if(mm12)

throw new Exception("Invalid Month");

if(dd==31 && (mm==02 || mm==04 || mm==06 || mm==9 || mm==11))

throw new Exception("Invalid Day");

if(dd==29 && mm==02 && !this.isLeapYear(yy))

throw new Exception("Invalid February Day");

if(yy9999)

throw new Exception("Invalid Year");

this.month= mm;

this.day= dd;

this.year= yy;

}

catch(Exception e)

{

System.out.println(e.getMessage());

this.month=this.day=this.year=0;

}

}

public String toString()

{

String mm="";

String dd="";

String yy="";

if(this.month

mm="0"+String.valueOf(this.month);

else

mm=String.valueOf(this.month);

if(this.day

dd="0"+String.valueOf(this.day);

else

dd=String.valueOf(this.day);

yy=String.valueOf(this.year);

return mm+ "/" +dd + "/" + yy;

}

}

// Time Class

class Time {

private int hour;

private int minute;

public Time(String t)

{

try{

if(t.length()!=5 || t.charAt(2)!=':')

throw new Exception("Invalid Time Format");

int hh=Integer.parseInt(t.substring(0,2));

int mm=Integer.parseInt(t.substring(3));

if(hh24)

throw new Exception("Invalid Hour");

if(mm60)

throw new Exception("Invalid Minutes");

this.hour=hh;

this.minute=mm;

}

catch(Exception e)

{

System.out.println(e.getMessage());

this.hour=this.minute=0;

}

}

public String toString()

{

String hh="";

String mm="";

if(this.minute

mm="0"+String.valueOf(this.minute);

else

mm=String.valueOf(this.minute);

if(this.hour

hh="0"+String.valueOf(this.hour);

else

hh=String.valueOf(this.hour);

return hh+":"+mm;

}

}

//Person Class

class Person {

private Name name;

private Date dateOfBirth;

public Person(String aFName,String aLName,String aDate){

this.name=new Name(aFName,aLName);

this.dateOfBirth=new Date(aDate);

}

public void setName(String aFName,String aLName)

{

this.name=new Name(aFName,aLName);

}

public String getName()

{

return this.name.toString();

}

public void setDateOfBirth(String aDate)

{

this.dateOfBirth=new Date(aDate);

}

public String getDateOfBirth()

{

return this.dateOfBirth.toString();

}

public String toString()

{

return "Name : "+this.getName()+" , Date of Birth : "+this.getDateOfBirth() + " ";

}

}

//Patient Class

class Patient extends Person{

private String employer;

private String insuranceCompany;

private Treatment[] treatments;

private static int treatmentCount;

public Patient(String aFName,String aLName,String aDate,String anEmployer,String anInsuranceCompany)

{

super(aFName,aLName,aDate);

this.employer=anEmployer;

this.insuranceCompany=anInsuranceCompany;

this.treatments=new Treatment[10];

this.treatmentCount=0;

}

public void associateWithTreatment(Treatment aTreatment)

{

this.treatments[this.treatmentCount++]=aTreatment;

}

public String getAllTreatments()

{

String number=""; for(int i=0;i

}

public void setEmployer(String anEmployer)

{

this.employer=anEmployer;

}

public String getEmployer()

{

return this.employer;

}

public void setInsuranceCompany(String anInsuranceCompany)

{

this.insuranceCompany=anInsuranceCompany;

}

public String getInsuranceCompany()

{

return this.insuranceCompany;

}

public String tellAboutSelf()

{

return this.toString()+" Employer: "+this.getEmployer()+" Insurance Company: "+this.insuranceCompany;

}

}

//Doctor Class

class Doctor extends Person{

private Date dateEmployed;

private String speciality;

public Doctor(String aFName,String aLName,String bDate,String aDateEmployed,String aSpeciality)

{

super(aFName,aLName,bDate);

this.dateEmployed=new Date(aDateEmployed);

this.speciality=aSpeciality;

}

public void setDateEmployed(String aDate)

{

this.dateEmployed=new Date(aDate);

}

public String getDateEmployed()

{

return this.dateEmployed.toString();

}

public void setSpeciality(String aSpeciality)

{

this.speciality=aSpeciality;

}

public String getSpeciality()

{

return this.speciality;

}

public String tellAboutSelf()

{

return this.toString()+" Date Employed : "+this.getDateEmployed()+" Speciality : "+this.getSpeciality();

}

}

//Name Class

class Name {

private String firstName;

private String lastName;

public Name(String aFirstName,String aLastName)

{

if(aFirstName!=null && aLastName!=null)

{

this.firstName=aFirstName;

this.lastName=aLastName;

}

}

public String toString()

{

if(this.firstName!=null && this.lastName!=null)

return this.lastName+", "+this.firstName;

else

return "";

}

}

//Treatment Class

class Treatment{

public Date treatmentDate;

public Time startTime;

public Time endTime;

public Patient aPerson;

public Treatment(String aDate,String sTime,String eTime,Patient aPerson)

{

this.treatmentDate=new Date(aDate);

this.startTime=new Time(sTime);

this.endTime=new Time(eTime);

this.aPerson=aPerson;

}

public String getTreatmentDate()

{

return this.treatmentDate.toString();

}

public String getStartTime()

{

return this.startTime.toString();

}

public String getEndTime()

{

return this.endTime.toString();

}

public String toString()

{

return "Treatment Date: "+this.treatmentDate.toString()+" , Start Time: "+this.startTime.toString()+" , End Time : "+this.endTime.toString()+" , Patient "+this.aPerson.toString()+" ";

}

}

and here is the test code that goes along with it:

public class DemoPerson { public static void main(String[] args) { try { //create doctors Doctor person1 = new Doctor("Peter", "Washington", "01/03/2000", "02/28/2001", "Internal Medicine"); Doctor person2 = new Doctor("Mary", "Adams", "04/05/1987", "04/06/1998", "General Surgery"); //create patients Patient person3 = new Patient("Paul", "Jefferson", "02/28/2016", "Ebay", "Insurance of Omaha"); Patient person4 = new Patient("Mama", "Casselliot", "02/02/2016", "PayPal", "Travelers Insurance"); //create treatments new Treatment("08/04/2015", "01:00", "01:20", person3); new Treatment("08/05/2015", "02:00", "02:20", person3); new Treatment("08/06/2015", "03:00", "03:20", person4); new Treatment("08/07/2015", "04:00", "04:20", person3); new Treatment("09/08/2015", "10:00", "10:20", person4);

//output people System.out.println( person1.tellAboutSelf() + " " + person2.tellAboutSelf() + " " + person3.tellAboutSelf() + " " + person4.tellAboutSelf() + " ");

//output treatments System.out.println( person3.getAllTreatments() + " " + person4.getAllTreatments() + " "); } catch (Exception e) { System.out.println("Error: Exception Thrown " + e.getMessage()); } }//end of main }//end of class

when I run the code above, the output should be the following:

I need help making my code work properly! Here is what I

However, when I run the code the treatment information is missing. Any help to get the treatment information up would be appreciated

JGRASP exec: java DemoPerson Doctor: Washington, Peter Born: 01/03/2000 Specialty: Internal Medicine Hire Date 02/28/2001 Doctor: Adams, Mary Born: 04/05/1987 Specialty: General Surgery Hire Date: 04/06/1998 Patient: Jefferson, Paul Bon: 02/28/2016 Employer: Ebay Insurance Insurance of Omaha Patient: Casselliot, Mama Born: 02/02/2016 Employer: PayPal Insurance Travelers Insurance Treatments for Patient Jefferson, Paul include: Treatment 1 dated 08/04/2015 started at 01:00 and ended at 01:20 Treatment 2 dated 08/05/2015 started at 02:00 and ended at 02:20 Treatment 3 dated 08/07/2015 started at 04:00 and ended at 04:20 Treatments for Patient Casselliot, Mama include: Treatment 1 dated 08/06/2015 started at 03:00 and ended at 03:20 Treatment 2 dated 09/08/2015 started at 10:00 and ended at 10:20 --jGRASP operation complete. JGRASP exec: java DemoPerson Doctor: Washington, Peter Born: 01/03/2000 Specialty: Internal Medicine Hire Date 02/28/2001 Doctor: Adams, Mary Born: 04/05/1987 Specialty: General Surgery Hire Date: 04/06/1998 Patient: Jefferson, Paul Bon: 02/28/2016 Employer: Ebay Insurance Insurance of Omaha Patient: Casselliot, Mama Born: 02/02/2016 Employer: PayPal Insurance Travelers Insurance Treatments for Patient Jefferson, Paul include: Treatment 1 dated 08/04/2015 started at 01:00 and ended at 01:20 Treatment 2 dated 08/05/2015 started at 02:00 and ended at 02:20 Treatment 3 dated 08/07/2015 started at 04:00 and ended at 04:20 Treatments for Patient Casselliot, Mama include: Treatment 1 dated 08/06/2015 started at 03:00 and ended at 03:20 Treatment 2 dated 09/08/2015 started at 10:00 and ended at 10:20 --jGRASP operation complete

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!