Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program to design an appointment calender. An appointment includes

ID: 3701018 • Letter: W

Question

Write a java program to design an appointment calender. An appointment includes the date, starting time,
ending time, and a description; for example,

Dentist 2012/10/1 17:30 18:30
CSl class 2012/10/2 08:30 10:00

Supply a user interFace to add appointment, remove canceled appointments, and print out
a list of appointments for a particular day. Follow the design process that was described
in this chapter. Your solution should include a class Appointment - Calender that is not coupled
with the Scanner or PrintStream Classes.

Explanation / Answer

package com.shyam.calendar;

import com.shyam.calendar.gui.CalFrame;

/**
* This launches the calendar application by running the main object.
*
* @version 1.0
**/
public class CalApp {

/** Creates new CalApp */
public CalApp() {
}
  
/**
* @param args the command line arguments
**/
public static void main (String args[]) {
//Construct a CalFrame object and start the calendar running.
try {
CalFrame f = new CalFrame("Calendar");
f.pack();
f.run();
}
catch(Exception e) {
e.printStackTrace();   
}
}
}


package com.shyam.calendar.data;

import org.w3c.dom.*;

/**
* Stores the data of an appointment
*
* @version 1.0
*/
public class Appt {
  
/** Used to represent time isn't set */
private static final int NO_TIME = -1;
  
/** Used to represent that there is no reminder */
public static final int NO_REMINDER = -1;
  
/** Used for setting appointments to recur weekly */
public static final int RECUR_BY_WEEKLY = 1;
  
/** Used for setting appointments to recur montly */
public static final int RECUR_BY_MONTHLY = 2;
  
/** Used for setting appointments to recur yearly */
public static final int RECUR_BY_YEARLY = 3;
  
/** Used for setting appointments to recur forever */
public static final int RECUR_NUMBER_FOREVER = 1000;
  
/** Used for setting appointments to never recur */
public static final int RECUR_NUMBER_NEVER = 0;
  
/** Used for knowing whether or not an appointment is valid or not */
private boolean valid;

/** The starting hour of the appointment */
private int startHour;
  
/** The starting minute of the appointment */
private int startMinute;
  
/** The starting day of the appointment */
private int startDay;
  
/** The starting month of the appointment */
private int startMonth;
  
/** The starting year of the appointment */
private int startYear;
  
/** The duration of the appointment (minutes) */
private int duration;
  
/** The title or caption of the appointment */
private String title;
  
/** The description of the appointment */
private String description;
  
/** The location of the appointment */
private String location;
  
/** Minutes before the appointment starts to set an alarm */
private int alarmTime;
  
/** E-mail address associated with the appointment */
private String emailAddress;
  
/** Web page address associated with the appointment */
private String webAddress;
  
/** Element location of the appointment in XML tree */
private Element xmlElement;
  
/** Day(s) of the week that the appointment recurs on */
private int[] recurDays;
  
/** What the appointment recurs on (weeks/months/years) */
private int recurBy;
  
/** How often the appointment recurs on (every ? weeks/months/years) */
private int recurIncrement;
  
/** How many recurrences (-1 for infinite, 0 by default) */
private int recurNumber;
  
/**
* Default constructor
* Constructs an invalid appointment
*/
public Appt() {
setTitle(null);
setDescription(null);
setLocation(null);
setEmailAddress(null);
setWebAddress(null);
setXmlElement(null);
  
valid = false;
}

/**
* Constructs a new appointment that starts at a specific time on the
* date specified. The appointment is constructed with no recurrence
* information by default. To set recurrence information, construct the
* appointment and then call setRecurrence(...) method. The XmlElement
* will be set when the appointment is saved to disk.
* @param startHour The hour that the appointment starts on. The hours are
* numbered 0-23 to represent 12a.m. to 11pm on the day specified.
* @param startMinute The minute of the hour the appointment starts on.
* @param startDay The day of the month the appointment starts on.
* @param startMonth The month of the year the appointment starts on. Use
* the constants provided by Gregorian Calendar to set the month.
* @param startYear The year the appointment starts on.
* @param duration The duration of the appointment (in minutes)
* @param title The title or caption to give the appointment
* @param description The appointment's details
* @param location Where the appointment occurs
* @param alarmTime Number of minutes before the start time to show reminder
* @param emailAddress An e-mail address associated with the appointment
* @param webAddress A web address associated with the appointment
*/
public Appt(int startHour, int startMinute,
int startDay, int startMonth, int startYear,
int duration, String title, String description, String location,
int alarmTime, String emailAddress, String webAddress) {

//Sets all instance variables except recurring information
setStartHour(startHour);
setStartMinute(startMinute);
setStartDay(startDay);
setStartMonth(startMonth);
setStartYear(startYear);
setDuration(duration);
setTitle(title);
setDescription(description);
setLocation(location);
setAlarmTime(alarmTime);
setEmailAddress(emailAddress);
setWebAddress(webAddress);
  
//Set default recurring information
int[] recurringDays = new int[0];
setRecurrence(recurringDays, RECUR_BY_MONTHLY, 0, RECUR_NUMBER_NEVER);
  
//Leave XML Element null
setXmlElement(null);
  
//Sets valid to true - this is now a valid appointment
valid = true;
}
  
/**
* Constructs a new appointment that has no start time on the
* date specified. The appointment is constructed with no recurrence
* information by default. To set recurrence information, construct the
* appointment and then call setRecurrence(...) method. The XmlElement
* will be set when the appointment is saved to disk.
* @param startDay The day of the month the appointment starts on
* @param startMonth The month of the year the appointment starts on. Use
* the constants provided by Gregorian Calendar to set the month.
* @param startYear The year the appointment starts on.
* @param title The title or caption to give the appointment
* @param description The appointment's details
* @param location Where the appointment occurs
* @param emailAddress An e-mail address associated with the appointment
* @param webAddress A web address associated with the appointment
*/
public Appt(int startDay, int startMonth, int startYear,
String title, String description, String location,
String emailAddress, String webAddress) {
  
//Just call the other constructor
this(NO_TIME, NO_TIME, startDay, startMonth, startYear, NO_TIME, title,
description, location, NO_TIME, emailAddress, webAddress);
}
  
/**
* Sets the recurring information with the correct information
*/
public void setRecurrence(int[] recurDays, int recurBy, int recurIncrement,
int recurNumber) {
setRecurDays(recurDays);
setRecurBy(recurBy);
setRecurIncrement(recurIncrement);
setRecurNumber(recurNumber);
}
  
/**
* Checks to see if an appointment occurs on a certain day, month, year.
* Takes recurrence into account.
* @return True if the appointment occurs on a certain day/month/year
* @deprecated
*/
public boolean isOn(int day, int month, int year) {
return (day == getStartDay() && month == getStartMonth()
&& year == getStartYear());
}
  
/**
* Checks to see if an appointment recurrs or not
* @return True if the appointment does occur more than once
*/
public boolean isRecurring() {
return getRecurNumber() != RECUR_NUMBER_NEVER;
}
  
/**
* Checks to see if a time is set for this appointment.
* @return True if this appointment has a time set. Otherwise false.
*/
public boolean hasTimeSet() {
return (getStartHour() != NO_TIME);
}
  
/**
* @return True if the appointment is valid
*/
public boolean isValid() {
return valid;
}
  
/**
* Sets the XML Element for this appointment
*/
public void setXmlElement(Element xmlElement) {
this.xmlElement = xmlElement;
}
  
/** Sets startHour */
private void setStartHour(int startHour) {
this.startHour = startHour;
}
  
/** Sets startHour */
private void setStartMinute(int startMinute) {
this.startMinute = startMinute;
}
  
/** Sets startDay */
private void setStartDay(int startDay) {
this.startDay = startDay;
}
  
/** Sets startMonth */
private void setStartMonth(int startMonth) {
this.startMonth = startMonth;
}
  
/** Sets startYear */
private void setStartYear(int startYear) {
this.startYear = startYear;
}
  
/** Sets duration */
private void setDuration(int duration) {
this.duration = duration;
}
  
/** Sets title */
private void setTitle(String title) {
if (title == null)
this.title = "";
else
this.title = title;
}
  
/** Sets description */
private void setDescription(String description) {
if (description == null)
this.description = "";
else
this.description = description;
}
  
/** Sets location */
private void setLocation(String location) {
if (location == null)
this.location = "";
else
this.location = location;
}
  
/** Sets alarmTime */
private void setAlarmTime(int alarmTime) {
this.alarmTime = alarmTime;
}
  
/** Sets emailAddress */
private void setEmailAddress(String emailAddress) {
if (emailAddress == null)
this.emailAddress = "";
else
this.emailAddress = emailAddress;
}
  
/** Sets webAddress */
private void setWebAddress(String webAddress) {
if (webAddress == null)
this.webAddress = "";
else
this.webAddress = webAddress;
}

/** Sets recurDays */
private void setRecurDays(int[] recurDays) {
if (recurDays == null) {
this.recurDays = new int[0];
}
else {
this.recurDays = recurDays;
}
}
  
/** Sets recurBy */
private void setRecurBy(int recurBy) {
this.recurBy = recurBy;
}
  
/** Sets recurIncrement */
private void setRecurIncrement(int recurIncrement) {
this.recurIncrement = recurIncrement;
}
  
/** Sets recurNumber */
private void setRecurNumber(int recurNumber) {
this.recurNumber = recurNumber;
}
  
/** Gets startHour */
public int getStartHour() {
return startHour;
}
  
/** Gets startHour */
public int getStartMinute() {
return startMinute;
}
  
/** Gets startDay */
public int getStartDay() {
return startDay;
}
  
/** Gets startMonth */
public int getStartMonth() {
return startMonth;
}
  
/** Gets startYear */
public int getStartYear() {
return startYear;
}
  
/** Gets duration */
public int getDuration() {
return duration;
}
  
/** Gets title */
public String getTitle() {
return title;
}
  
/** Gets description */
public String getDescription() {
return description;
}
  
/** Gets location */
public String getLocation() {
return location;
}
  
/** Gets alarmTime */
public int getAlarmTime() {
return alarmTime;
}
  
/** Gets emailAddress */
public String getEmailAddress() {
return emailAddress;
}
  
/** Gets webAddress */
public String getWebAddress() {
return webAddress;
}

/** Gets recurDays */
public int[] getRecurDays() {
return recurDays;
}
  
/** Gets recurBy */
public int getRecurBy() {
return recurBy;
}
  
/** Gets recurIncrement */
public int getRecurIncrement() {
return recurIncrement;
}
  
/** Gets recurNumber */
public int getRecurNumber() {
return recurNumber;
}
  
/** Gets xmlElement */
public Element getXmlElement() {
return xmlElement;
}

/** Returns a simple string representing the appointment */
public String toString() {
if (!isValid()) {
return null;
}
else {
if (hasTimeSet()) {
return getStartHour() + ":" + getStartMinute() + " " + getTitle();
}
else {
return getTitle();
}
}
}
}

package com.shyam.calendar.data;

import java.util.*;

/**
* Stores all of the appointments of a single calendar day. It also
* has some useful calendar-related abilities, such as the ability
* to create a new calendar day that is incremented by a day.
*
* @version 1.0
*/
public class CalDay {

/** Collection of all of the appointments for the calendar day */
/* Note that a LinkedList retains order */
LinkedList appts;
  
/** Stores whether or not this is a valid calendar day */
boolean valid;
  
/** Stores the calendar day */
int day;
  
/** Stores the calendar month */
int month;
  
/** Stores the calendar year */
int year;
  
/**
* Default constructor
* Constructs an invalid CalDay object
*/
public CalDay() {
valid = false;
}
  
/**
* Constructor
* Creates a new CalDay which is ready for appointments to be
* added to it. Note that months are numbered 0 through 11. This does
* not check to see if a date is valid.
*/
public CalDay(GregorianCalendar cal) {
  
int day = cal.get(cal.DAY_OF_MONTH);
int month = cal.get(cal.MONTH);
int year = cal.get(cal.YEAR);
  
setDay(day);
setMonth(month);
setYear(year);
  
setAppts(new LinkedList());
  
valid = true;
}
  
/**
* Adds an appointment to the calendar day object. The appointments are
* kept in order by start time. Note that this does not check to see if
* the appointment actually occurs on this day. This is so the recurring
* appointments can be added. The appointment can also be added twice.
*/
public void addAppt(Appt appt) {
if (valid) {
for (int i = 0; i < getAppts().size(); i++) {
//Put the appointment in the correct order - finish this
if (((Appt)getAppts().get(i)).getStartHour() >
appt.getStartHour()) {
  
getAppts().add(i, appt);
return;
}
}
//The appointment hasn't been added yet, so add it
getAppts().add(appt);
}
}
  
/**
* @return True if this is an initalized CalDay object
*/
public boolean isValid() {
return valid;
}
  
/**
* This returns an iterator of Appt objects for the calendar day. The
* appointments are added after the CalDay is constructed. The appointments
* are guaranteed to be in order by time, with appointments with no specific
* time set placed at the beginning.
*/
public Iterator iterator() {
if (isValid()) {
return getAppts().iterator();
}
else {
return null;
}
}
  
/** Sets appts */
private void setAppts(LinkedList appts) {
this.appts = appts;
}
  
/** Sets day */
private void setDay(int day) {
this.day = day;
}
  
/** Sets month */
private void setMonth(int month) {
this.month = month;
}
  
/** Sets year */
private void setYear(int year) {
this.year = year;
}
  
/** Gets appts */
public LinkedList getAppts() {
return appts;
}
  
/** Gets day */
public int getDay() {
return day;
}
  
/**
* Gets the month represented by this calDay. Note that January-December
* are represented by 0-11
*/
public int getMonth() {
return month;
}
  
/** Gets year */
public int getYear() {
return year;
}
  
/**
* Returns a string representation of the date represented in
* the format of MM/DD/YYYY. If someone where to ask what day of the
* year this CalDay was for, and they called this method, that would
* be the answer. No further adjustment would be necessary. Useful for
* debugging.
*/
public String toString() {
return (getMonth()+1) + "/" + getDay() + "/" + getYear();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote