Comment this code using javadoc. package bcs345.hwk.schedule.business; import ja
ID: 3697890 • Letter: C
Question
Comment this code using javadoc.
package bcs345.hwk.schedule.business;
import java.io.PrintStream;
import java.util.Scanner;
public class PersonAppointments {
private String First;
private String Last;
private Appointment[] Appointments;
public PersonAppointments() {
First = "";
Last = "";
Appointments = new Appointment[10];
}
public String getFirst() {
return First;
}
public void setFirst(String first) {
First = first;
}
public String getLast() {
return Last;
}
public void setLast(String last) {
Last = last;
}
public Appointment GetByDateTime(ScheduleDate date, ScheduleTime time) {
for (int i = 0; i < Appointments.length; i++) {
if ((Appointments[i].getDate().toString().equals(date.toString()))
&& (Appointments[i].getTime().toString().equals(time.toString())))
return Appointments[i];
}
return null;
}
public Appointment GetByIndex(int index) throws ArrayIndexOutOfBoundsException, NullPointerException {
if (Appointments == null)
throw new NullPointerException("Appoinment array is null");
if (index < 0 || index > Appointments.length - 1)
throw new ArrayIndexOutOfBoundsException();
return Appointments[index];
}
public void Report(PrintStream ps) {
int amApp = 0;
int pmApp = 0;
ps.println("Schedule Report");
ps.println("--------------");
ps.println("First: " + First);
ps.println("Last: " + Last);
ps.println(" M D Y Hr Mn Pd Category Description");
ps.println(" - - - -- -- -- -------- -----------");
for (int i = 0; i < Appointments.length; i++) {
ScheduleDate d = Appointments[i].getDate();
ScheduleTime t = Appointments[i].getTime();
if (t.getPeriod().equalsIgnoreCase("am")) {
amApp++;
} else {
pmApp++;
}
String categ = Appointments[i].getCategory();
String desc = Appointments[i].getDescription();
ps.format("%2d %2d %4d %2d %02d %2s %12s %20s ", d.getMonth(), d.getDay(), d.getYear(), t.getHour(),
t.getMinute(), t.getPeriod(), categ, desc);
}
ps.println(" Summary");
ps.println("--------");
ps.println("AM appointments:" + amApp);
ps.println("PM appointments:" + pmApp);
}
public void Write(PrintStream ps) {
ps.println(First);
ps.println(Last);
ps.println(Appointments.length);
for (int i = 0; i < Appointments.length; i++) {
Appointments[i].Write(ps);
}
}
public void Read(Scanner s) {
First = s.nextLine();
Last = s.nextLine();
int appCount = Integer.parseInt(s.nextLine());
Appointments = new Appointment[appCount];
for (int i = 0; i < Appointments.length; i++) {
Appointment app = new Appointment();
app.Read(s);
Appointments[i] = app;
}
}
public String GetJSON() {
String str = "{ "first" : " + First + ", "last" : " + Last + ", "appts" : [ ";
for (int i = 0; i < Appointments.length-1; i++) {
str += Appointments[i].GetJSON()+", ";
}
str += Appointments[Appointments.length-1].GetJSON()+" ] }";
return str;
}
@Override
public String toString() {
String str="First: "+First+" Last: "+Last+" Appointments: ";
for (int i = 0; i < Appointments.length; i++) {
str+=Appointments[i]+" ";
}
return str;
}
}
Explanation / Answer
Compiling this class solely will compile to errors. Reason is, the supporting classes Appointments, ScheduleDate, ScheduleTime are needed which are not provided.
This class deals with the management of appointments of a person.
1)
public PersonAppointments() {
First = "";
Last = "";
Appointments = new Appointment[10];
}
The class consists of a default constructor where an array of 10 appointments is created. This explicitly says that the class is defined to handle only 10 appointments.
2)
public String getFirst() {
return First;
}
public void setFirst(String first) {
First = first;
}
public String getLast() {
return Last;
}
public void setLast(String last) {
Last = last;
}
Setter and getter methods are defined to read and assign the first and last names of the person
3)
public Appointment GetByDateTime(ScheduleDate date, ScheduleTime time) {
for (int i = 0; i < Appointments.length; i++) {
if ((Appointments[i].getDate().toString().equals(date.toString()))
&& (Appointments[i].getTime().toString().equals(time.toString())))
return Appointments[i];
}
return null;
}
This method retrieves the appointment details on a particular date and time which are passed as parametes as ScheduledTime and ScheduledDate.
4)
public void Read(Scanner s) {
First = s.nextLine();
Last = s.nextLine();
int appCount = Integer.parseInt(s.nextLine());
Appointments = new Appointment[appCount];
for (int i = 0; i < Appointments.length; i++) {
Appointment app = new Appointment();
app.Read(s);
Appointments[i] = app;
}
}
This method is used to read the appointment details fromt he console at the run time. After reading is done, the appointments are written to a file using the method Write()
public void Write(PrintStream ps) {
ps.println(First);
ps.println(Last);
ps.println(Appointments.length);
for (int i = 0; i < Appointments.length; i++) {
Appointments[i].Write(ps);
}