I created a java program that stores health professionals record and allows them to create a schedule book for each individual professionals.
here's my record class to record appointments
import java.time.LocalDate;
import java.time.LocalTime;
public class record
{
private String treatment;
private LocalDate date;
private LocalTime endTime;
private LocalTime startTime;
public record(String treatment,LocalDate date,LocalTime endTime,LocalTime startTime)
{
this.treatment = treatment;
this.date=date;
this.endTime = endTime;
this.startTime=startTime;
}
public LocalTime getStartTime() {
return startTime;
}
public String getTreatment()
{
return treatment;
}
public LocalTime getEndTime()
{
return endTime;
}
public LocalDate getDate()
{
return date;
}
public String printRec()
{
String info;
info = "Treatement Type: " + treatment +" start time: "+startTime + " end time : "+endTime;
return info;
}
}
Here's the health professional class
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
public class doctor
{
private String name;
private String profession;
private String office;
public record parent;
final ArrayList<record> records = new ArrayList<>();
LocalDate date;
LocalTime time;
public doctor(String name,String profession,String office)
{
this.name=name;
this.profession=profession;
this.office=office;
}
public String getName()
{
return name;
}
public String getProfession()
{
return profession;
}
public String getOffice()
{
return office;
}
record addRecord(String treatment, LocalDate date, LocalTime start, LocalTime end) {
final record holdRecord = new record(treatment, date, end, start);
records.add(holdRecord);
return holdRecord;
}
List<record> getRecords()
{
return records;
}
public void setOffice(String location) {
this.office=location;
}
public void setName(String name) {
this.name=name;
}
public void setProfession(String prof) {
this.profession=prof;
}
public String printInfo()
{
String info;
info = "name: " + name +"; profession: "+profession + "; office: "+office;
return info;
}
}
and here's the main class that handles the program
import java.util.ArrayList;
import java.util.Iterator;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class runCode
{
LocalDate date;
LocalTime time;
private doctor doc;
ArrayList<record>profRec=new ArrayList();
ArrayList<doctor>healthProf=new ArrayList();
public void run()
{
addProf();
edit();
print();
}
public void addProf()
{ String firstName=getInput("Enter first name: ").toLowerCase().trim();
String lastName=getInput("Enter last name: ").toLowerCase().trim();
String name=firstName+" "+lastName;
String profession=getInput("Enter profession: ").trim();
String office=getInput("Enter your work address: ").trim();
doc=new doctor(name,profession,office);
healthProf.add(doc);
System.out.println("added");
}
public void delete()
{
System.out.println("Which health professional's record would you like to delete ");
int x=Genio.getInteger()-1;
if(healthProf.size()==0)
System.out.println("The list is empty, add a value ");
else if(healthProf.size() !=0 && x>=0 && x<=healthProf.size())
{
healthProf.remove(x);
System.out.println("deleted ");
}
else
{
System.out.println("Wrong input try again");
}
}
public void edit()
{
System.out.println("Which health proffessional's record would you like to edit");
int x=Genio.getInteger()-1;
System.out.println("What do you like to edit");
if(healthProf.size()==0)
System.out.println("The list is empty, add a value ");
else if(healthProf.size() !=0 && x>=0 && x<healthProf.size())
{
System.out.println("enter 1 to change name");
System.out.println("enter 2 to change office");
System.out.println("enter 3 to change profession");
int d=Genio.getInteger();
if(d==1)
{
String firstName=getInput("Enter first name: ").toLowerCase().trim();
String lastName=getInput("Enter last name: ").toLowerCase().trim();
String newName=firstName+" "+lastName;
healthProf.get(x).setName(newName);
}
else if(d==2)
{
System.out.println("Enter your new work addreess: ");
String newOffice=Genio.getString();
healthProf.get(x).setOffice(newOffice);
}
else if(d==3)
{
System.out.println("Enter your new profession: ");
String newProfession=Genio.getString();
healthProf.get(x).setProfession(newProfession);
}
else
{
System.out.println("Wrong input try again");
}
System.out.println("change saved");
}
else
System.out.println("Wrong input try again");
}
public LocalDate date()
{
while (true)
{
try
{
System.out.println("Input the date :");
String input = Genio.getString();
String[] store = input.split("/");
int day = Integer.parseInt(store[0]);
int month = Integer.parseInt(store[1]);
int year = Integer.parseInt(store[2]);
return date = date.of(year, month, day);
}catch(Exception de)
{
System.out.println("An error occured try again");
continue;
}
}
}
public LocalTime time() {
while (true)
{
try
{
System.out.println("Input the time use 24-clock format :");
String inputTime = Genio.getString();
String[] storeTime = inputTime.split(":");
int hour = Integer.parseInt(storeTime[0]);
int minute = Integer.parseInt(storeTime[1]);
time = time.of(hour, minute);
break;
}catch(Exception de)
{
System.out.println("An error occured try again");
continue;
}
}
return time;
}
public void print()
{
int count=0;
for(doctor doc:healthProf)
{
count++;
System.out.println(count+" "+doc.printInfo());
}
count=0;
}
public void printAppointment()
{
System.out.println("Select the health professional: ");
int x=Genio.getInteger()-1;
int count=0;
Iterator<record> it = healthProf.get(x).getRecords().iterator();
Iterator<record> it2 = healthProf.get(x).getRecords().iterator();
while(it.hasNext()) {
while(it2.hasNext())
{
System.out.println(it2.next());
}
}
}
public void makeAppointment()
{
System.out.println("Select the health professional: ");
int x=Genio.getInteger()-1;
LocalTime start=time();
LocalTime end=time();
LocalDate date=date();
System.out.println("Input the treatment :");
String treatment= Genio.getString();
healthProf.get(x).addRecord(treatment,date,end,start);
}
public String getInput(String prompt)
{
System.out.println(prompt);
return Genio.getString();
}
}
So basically when you run the program you can create several health professional instances, each health professional is able to create appointment booking using the makeAppointment method. my problem is printing out the appointment for each health professional.
I tried printing it out with the print() method in the doctor class. it works but it prints out all the appointment bookings made not for the specific professional's appointment book.
Also, I tried printing it out with the printAppointment () method in the runCode class, but it prints out record@672f158f and is stuck in an infinite loop
What I have tried:
public void print()
{
int count=0;
for(Record rec:records)
{
count++;
System.out.println(count+" "+rec.printInfo());
}
count=0;
}
I've also tried
public void printAppointment()
{
System.out.println("Select the health professional: ");
int x=Genio.getInteger()-1;
int count=0;
Iterator<Record> it2 = healthProf.get(x).getRecords().iterator();
while(it2.hasNext())
{
System.out.println(it2.next());
}
}