Design Documentation:
Following are different classes used in our solution
1. Patient
2. Appointment
3. Driver
I:Patient Class:
This is the class to store all the information of [Link] consists of following attributes
• First Name
• Surname
• Telephone
• Date of Birth
• Country of origin.
It consists of following functions
Getters
Setters
Print(to print all the information of patient)
Constructor
II Appointment Class:
This is the class which is the core class of the [Link] involves multiple entities including
Doctor,Patient [Link] has the following attributes
Doctor Name
Patient Object
Time of Appointment
Technical Description:
Following is the flow of the code
User enters the choice between 1 to 5 and if the user enters any value other than 1 to 5,error is
showed.
Now there are different if statements to handle the different options like
If userchoice==1 then Book appointment is handled
In this patients information is inputted along with the time of [Link] an object of patient
is made from this [Link] all the available doctors are showed at that time by checking free
slot in each doctor [Link] user enters Doctors name and then the appointment is booked.
If userchoice==2 then cancel appointment is handled
In this user enters doctors name and timeslot of appointment and then the appointment at that time
with doctor is cancelled by freeing the slot of the doctor by changing it to free.
If userchoice==3 then doctors schedule is displayed
In this the user enters doctors name and then all the schedule of that that doctor is displayed using
the schedule of all the doctors and using if statement to show schedule of only that doctor.
If userchoice==4 then patients appointment is shown
In this the user enters patients first and sur name and then all the appointments of that patient is
displayed by searching the arraylist of appointments and where the patient name matches using if
[Link] patient information is displayed using print function of patient class.
Array list is used to store all the appointments and the on book appointment new appointment is
added in that array list and on cancel appointment that appointment is removed from arraylist.
Test Plan:
To test the correctness of the code we will use this flow
User will enter the choice 1
Then all the information required for book appointment is entered and then appointment is booked.
Then user will enter choice 3 to see the doctors schedule and the above appointment with the doctor
will be shown.
Then user will enter choice 4 to see the Patients schedule and the above appointment of the patient
will be shown.
Then user will enter choice 2 to Cancel appointment and the then choice 3 and choice 4 will again be
[Link] appointment shall be shown.
Lastly user will enter choice 5 and program will exit.
Development:
Following are the screenshot of the code using all the choices.
Choice1:
Choice3:
Choice4:
Choice2:
Choice5:
The program source code:
[Link]:
public class Patient {
String firstname;
String Surname;
String Telephone;
String DOB;
String Country;
public Patient() {
firstname="";
Surname="";
Telephone="";
DOB="";
Country="";
}
public Patient(String a,String b,String c,String d,String e) {
firstname=a;
Surname=b;
Telephone=c;
DOB=d;
Country=e;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
[Link] = firstname;
}
public String getSurname() {
return Surname;
}
public void setSurname(String surname) {
Surname = surname;
}
public String getTelephone() {
return Telephone;
}
public void setTelephone(String telephone) {
Telephone = telephone;
}
public String getDOB() {
return DOB;
}
public void setDOB(String dOB) {
DOB = dOB;
}
public String getCountry() {
return Country;
}
public void setCountry(String country) {
Country = country;
}
public void print() {
[Link]("First Name :"+firstname);
[Link]("Sur Name :"+Surname);
[Link]("Telephone Number :"+Telephone);
[Link]("Date of Birth :"+DOB);
[Link]("Country :"+Country);
[Link]:
public class Appointment {
String Doctor_name;
Patient patient;
String time;
public Appointment(String a,Patient b,String c) {
Doctor_name=a;
patient=b;
time=c;
}
}
[Link]:
import [Link];
import [Link];
public class Driver {
public static Boolean isavailable(String [] slots,String time) {
for(int i=0;i<[Link];++i) {
if(slots[i].equals(time)) {
return true;
}
}
return false;
}
public static String[][] SetTimeSlotBooked(String DoctorName,String
Timeslot,String []DoctorsNames,String [][]schedule)
{
int docindex=-1;
for(int i=0;i<[Link];++i) {
if([Link](DoctorsNames[i])) {
docindex=i;
i+=[Link];
}
}
for(int i=0;i<schedule[docindex].length;++i) {
if(schedule[docindex][i].equals(Timeslot)) {
schedule[docindex][i]="Booked at "+schedule[docindex][i];
}
}
return schedule;
}
public static ArrayList<Appointment> removeAppointment(String
DoctorName,String Timeslot,ArrayList<Appointment>appointments){
for(int i=0;i<[Link]();++i) {
[Link]([Link](i).Doctor_name);
[Link]([Link](i).time);
if([Link](i).Doctor_name.equals(DoctorName) &&
[Link](i).[Link](Timeslot)) {
[Link](i);
}
}
return appointments;
}
public static String[][] SetTimeSlotFree(String DoctorName,String
Timeslot,String []DoctorsNames,String [][]schedule)
{
int docindex=-1;
for(int i=0;i<[Link];++i) {
if([Link](DoctorsNames[i])) {
docindex=i;
i+=[Link];
}
}
for(int i=0;i<schedule[docindex].length;++i) {
if(schedule[docindex][i].equals("Booked at "+Timeslot)) {
schedule[docindex][i]="Free";
}
}
return schedule;
public static void main(String[] args) {
ArrayList<Appointment> AllAppointments=new ArrayList<Appointment>();
String [] DoctorsNames= {"Dr. Todor Zhikov","Dr. Emil Constantinescu","Dr.
Steven Seagal","Dr. Igor Dondon"};
// String Doctor1="Dr. Todor Zhikov";
// String Doctor2="Dr. Emil Constantinescu";
// String Doctor3="Dr. Steven Seagal";
// String Doctor4="Dr. Igor Dondon";
String [][] schedule= {{"5pm","6pm","7pm","8pm"},{"6pm","7pm","8pm","9pm"},
{"11am","12pm","1pm","2pm"},{"9am","10am","11am","12am"}};
// String[] Doctpr1_schedule= {"5pm","6pm","7pm","8pm"};
// String[] Doctpr2_schedule= {"6pm","7pm","8pm","9pm"};
// String[] Doctpr3_schedule= {"11am","12pm","1pm","2pm"};
// String[] Doctpr4_schedule= {"9am","10am","11am","12am"};
while(true) {
// TODO Auto-generated method stub
[Link](" *************************");
[Link](" * MEDICARE *");
[Link](" *************************");
[Link]("1. Book an appointment");
[Link]("2. Cancel an appointment");
[Link]("3. View doctors schedule");
[Link]("4. View patient appointment");
[Link]("5. Exit");
Scanner myObj = new Scanner([Link]); // Create a Scanner object
[Link]("Please enter an option");
String userOption = [Link]();
if([Link]("1")) {
[Link]("Enter First Name");
String FirstName=[Link]();
[Link]("Enter Surname Name");
String SurName=[Link]();
[Link]("Enter Telephone Number");
String Telephone=[Link]();
[Link]("Enter Date of Birth");
String DOB=[Link]();
[Link]("Enter Country of origin");
String Country=[Link]();
Patient p1=new Patient(FirstName,SurName,Telephone,DOB,Country);
[Link]("Enter the timeslot for appointment i:e 6pm,8pm etc");
String Timeslot=[Link]();
[Link]("Following are the doctors available at this time");
for(int i=0;i<4;++i) {
if(isavailable(schedule[i],Timeslot)==true) {
[Link](DoctorsNames[i]);
}
}
[Link]("Enter Doctor name for appointment");
String DoctorName=[Link]();
[Link]("Your Appointment is succesfully booked");
schedule=SetTimeSlotBooked(DoctorName,Timeslot,DoctorsNames,schedule
);
Appointment app=new Appointment(DoctorName, p1, Timeslot);
[Link](app);
}
else if([Link]("2")) {
[Link]("Enter Doctor Name");
String DoctorName=[Link]();
[Link]("Enter TimeSlot");
String TimeSlot=[Link]();
schedule=SetTimeSlotFree(DoctorName,TimeSlot,DoctorsNames,schedule);
AllAppointments=removeAppointment(DoctorName,TimeSlot,AllAppointments
);
[Link]("Your Appointment is succesfully Cancelled");
}
else if([Link]("3")) {
[Link]("Enter Doctor Name");
String DoctorName=[Link]();
[Link]("This is the schedule of the Doctor");
int docindex=-1;
for(int i=0;i<[Link];++i) {
if([Link](DoctorsNames[i])) {
docindex=i;
i+=[Link];
}
}
for(int i=0;i<schedule[docindex].length;++i) {
if(!schedule[docindex][i].contains("Booked")) {
[Link]("Free at "+schedule[docindex][i]);
}
else {
[Link](schedule[docindex][i]);
}
}
}
else if([Link]("4")) {
[Link]("Enter Patients First Name");
String PatientFirstName=[Link]();
[Link]("Enter Patients Sur Name");
String PatientSurName=[Link]();
[Link]("These are the apointments of the patient");
int count=0;
for (int counter = 0; counter < [Link](); counter++) {
if([Link](counter).[Link]().equals(PatientFirstNam
e)) {
if([Link](counter).[Link]().equals(PatientSurName
))
{
count+=1;
[Link](counter).[Link]();
[Link]("Time:"+ [Link](counter).time);
[Link]("Doctor Name:"+
[Link](counter).Doctor_name);
}
}
}
if(count==0)
[Link]("No appointments");
}
else if([Link]("5")) {
[Link]("Exited");
break;
}
else {
[Link]("Wrong [Link] try again");
}
}
}