you will build a Medical Record System. This design will cover the key OOP conce
ID: 3701475 • Letter: Y
Question
you will build a Medical Record System. This design will cover the key OOP concepts of: UML diagrams, classes, objects, attributes, methods, encapsulation, messages, inheritance, polymorphism, exceptions and association relationships. In terms of Java, you will use sequencing, decision making, looping, arrays and method construction.
The UML Class diagram is included with the documentation. Here is a rundown of the classes necessary for the project.
Domain Classes
Person Class
The Person class is the primary Domain class for the project. It stores the basic data for a person within the system. It utilized two (2) other classes as attributes – Name and Date. It has the appropriate setters, getters and only one constructor.
Patient Class
The Patient class inherits from the Person class as a specific type of person. It contains the unique data for patients who receive treatment. This is the most complicated of the classes; especially, since it uses an array of class Treatment. Each Patient, in this system, can have from 0 to 10 treatments. When creating the Treatment attribute array, you need to declare it to hold 10 elements. It has the appropriate setters, getters and one constructor. The tellAboutSelf method is used to output the attribute data in a formatted string for display.
Doctor Class
The Doctor class inherits from the Person class as a specific type of person. It has the appropriate setters, getters and one constructor. The tellAboutSelf method is used to output the attribute data in a formatted string for display.
Treatment Class
Utility Classes
Name Class
The Name class is used to store the first and last name data for any type of Person. Both the first and last name’s must be provided. If one is null, neither should be set. The getFullName method is provided to return the full name in the format lastName, firstname.
Time Class
The Time class is used to store clock time of hours and minutes. Seconds are not necessary. The time is stored in International or military style. The hours attribute should store values from 0 to 24. No other value should be stored. If an invalid number is sent to Time, a zero should be stored. This is true of hours and minutes. Time is input in the format 00:00 as a string. No other format is to be accepted by the class.
The minute attribute should only store values from 0 to 60. Invalid values should result in 0 being stored. The toString method is the interface for this class and should return the time in the following format hour:minute (00:00). Single digits should be displayed with a leading zero (0) or as 01:00.
Date Class
The Date class is the most complicated of the utility classes. Its purpose is to store a valid date and when invalid, throw an exception. The attribute of month, day and year are integer values and should always be valid.
Date input – the date input to the constructor should be in a string formatted as mm/dd/yyyy. Any input not conforming to that format should throw an exception and store zeros (0) for all the attributes.
Month attribute – the month attribute should store the values 1 to 12. Any invalid month value should throw an exception.
Day attribute – the day attribute should store the appropriate value based on the month and leap year vs non-leap year for February. An invalid day for a month should throw an exception. For example, a day value of 31 is acceptable for January, but not for April. For February, 29 is acceptable if the year is a leap year, but not if not a leap year. Therefore, the class needs a method (isLeapYear) for determining whether the year input is a leap year or not. The method returns the Boolean TRUE if it is a leap year and FALSE if not.
Here is the algorithm for determining if a year is a leap year:
If the year is evenly divisible by 4, go to step 2.
If the year is evenly divisible by 100, go to step 3.
If the year is evenly divisible by 400, go to step 4.
The year is a leap year (it has 366 days, February 29.)
The year is not a leap year (it has 365 days, February 28.)
Year attribute – the year value is used to determine the leap year and should store values in the range of 1000 to 9999. Invalid year values should throw an exception.
Date Exceptions – The date class should throw an exception for the following reasons.
Time string not in the form of mm/dd/yyyy.
February’s day value is invalid.
Month value is invalid.
Day value for appropriate month is invalid.
Year value is invalid.
All methods that use the Date class should be designed to throw exceptions.
The user interface for this class is the toString method. It should be designed to return the date in the following string format – mm/dd/yyyy with leading zeros (0) for single digit values as in 01/02/2016.
Evaluation Program
Your project will be tested using the Demoperson.java file. You may use it to test your designs, but do not modify the file except for testing dates, times, etc.
Person Date Name firstName: String -lastName: String +Name(aFirst Na me String, aLastName String) +toString() String -name Name -dateOfBirth Date +Person(aFName : String, aLName String, aDate String) +setName(aFName String, aLName String +getName() String +setDateOfBirth(aDate String) +getDate OfBirth) String -month int -day int -year int Date() Date (aDate String) +isLea pYear(y: int) boolear +toString) String Patient Doctor employer String -insuranceCompany String -treatments Treatmentl -treatmentCount int +Patient(aFName String, aLName String, aDate String, anEmployer String, anlnsuranceCompany String) +associate WithTreatment(aTreatment Treatment) +getAllTreatments() String +setEmployer(anEmployer String) +getEmployer String +setinsura nce Company(anlnsuranceCo mpany String) +getinsuranceCompany) String +tellAboutSelf) String -dateEmployed Date -specialty String +Doctor(aFName String, aLName String, bDate: String, aDateEmployed String, aSpecialty: String) 1+setDate Employed(aDate String) +getDate Employed): String +setSpecialty(aSpecialty String) +getSpecialty() String +tellAboutSelf) String 0..10 Treatment -treatmentDate Date -startTime Time -endTime Time -aPerson: Patient +Treatment(aDate String, sTime String, eTime: String, aPerson: Patient) +getTreatment Date() String +getStartTime) String +getEndTime() String Time -hour: int minute int +Time(t :String) +Date(aDate String +toString(): StringExplanation / Answer
// 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(2,4));
yy=Integer.parseInt(aDate.substring(4,8));
if(mm<1 || mm>12)
throw new Exception("Invalid Month");
if(dd==31 && (mm==2 || mm==4 || mm==6 || mm==9 || mm==11))
throw new Exception("Invalid Day");
if(dd==29 && mm==2 && !this.isLeapYear(yy))
throw new Exception("Invalid February Day");
if(yy<1000 || yy>9999)
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<10)
mm="0"+String.valueOf(this.month);
else
mm=String.valueOf(this.month);
if(this.day<10)
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(2,4));
if(hh<0 || hh>24)
throw new Exception("Invalid Hour");
if(mm<0 || mm>60)
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<10)
mm="0"+String.valueOf(this.minute);
else
mm=String.valueOf(this.minute);
if(this.hour<10)
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 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 res="";
for(int i=0;i<this.treatmentCount;i++)
res+=this.treatments[i].toString();
return res;
}
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 {
private Date treatmentDate;
private Time startTime;
private Time endTime;
private 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()+" ";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.