Please dont answer if you cannot complete all the requiremen
Please don\'t answer if you cannot complete all the requirements. This question has been answered but it was incorrect!!!
You are to write the following PersonalCalendar, Event and Appointment classes and other interfaces or classes as necessary. Note that there is no main method required in this assignment; a JUnit test will be used instead.
Some details of the implementation are left to you. Other details are implied, but not stated directly, in the description. (That said, don\'t over think this; do the minimum required to perform the specified function.)
You are to write a class PersonalCalendar. Entries in a PersonalCalendar can be either an Event or an Appointment. Entries can be added to, returned from and removed from the PersonalCalendar.
An Event has a date consisting of ints for year, month, dayOfMonth, hour and minute. It also has a String description, a String location and an int duration in minutes. Events do not have attendees. Two Event objects are equal if their dates and descriptions are equal.
An Appointment has a date consisting of ints for year, month, dayOfMonth, hour and minute. It has an int duration in minutes and a String description. An Appointment also has an ArrayList of Strings for attendees. Attendees can be added to an Appointment. An Appointment does not have a location--that\'s assumed to be my office. Appointment has an equals method that compares dates and descriptions to determine equality.
A PersonalCalendar maintains its entries sorted by date, not the order the entries were inserted. Thus the first element of a PersonalCalendar is always the fist element chronologically, regardless of the order the elements were added. If two elements have exactly the same date and time, description is used to break the tie. (Hint: GregorianCalendar and Collections.sort. Also let your IDE help you write commonly used code.)
You are to write a JUnit test to verify that a PersonalCalendar object maintains its entries in the correct order.
Here are some bullets I will use in grading
PersonalCalendar accepts both Event and Appointment objects
PersonalCalendar does not accept objects such as String
PersonalCalendar keeps its content sorted appropriately
Event implements the specified function
Appointment implements the specified function
JUnit tests verify the following:
A PersonalCalendar with a single Appointment or Event contains the expected object.
A PersonalCalendar returns its objects sorted first by date and then description, regardless of the order the objects were added, and regardless of whether the items were all Events, or all Appointments, or a mixture.
My JUnit test class was long, but that was mostly because I did a lot of copy/paste for test setup. None my other components were more than 50 lines of code.
Solution
import java.util.GregorianCalendar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;
//Personal Calendar
class PersonalCalendar {
HashMap <GregorianCalendar, ArrayList<Event>> calendar;
//No arguments constructor
public AppointmentBook(){
calendar = new HashMap <GregorianCalendar, ArrayList<Event>>();
}
public boolean add(Event newEvent){
boolean success;
GregorianCalendar eventDate = newEvent.getStartDateAndTime();
int year = newEvent.getYear();
int month = newEvent.getMonth();
int day = newEvent.getDayOfMonth();
Date eventDate = new GregorianCalendar(year, month, day).getTime();
ArrayList<Event> currentList = calendar.get(eventDate);
if(currentList != null) {
if (currentList.contains(newEvent)){
success = false;
}
else{
currentList.add(newEvent);
calendar.remove(eventDate);
calendar.put(eventDate,currentList);
success = true;
}
}
else {
currentList = new ArrayList<Event>();
currentList.add(newEvent);
calendar.remove(eventDate);
calendar.put(eventDate,currentList);
success = true;
}
return success;
}
public ArrayList<Event> getEventsForDate(GregorianCalendar date){
ArrayList<Event> dateList = calendar.get(date);
//If there are no entries, return an empty ArrayList
if(dateList == null) {
dateList = new ArrayList<Event>();
}
return dateList;
}
//Event Class
abstract class Event{
int year, month, dayOfMonth, hour, minute, duration;
String desc;
String loc;
}
//Default Constructor
public Event() {
year = null;
month = null;
dayOfMonth = null;
hour = null;
minute = null;
duration = null;
desc = \"\";
loc = \"\";
}
//Parameterised Constructor
public Event(int year, int month, int dayOfMonth, int hour, int minute, int duration, String desc, String loc) {
this.year = year;
this.month = month;
this.dayOfMonth = dayOfMonth;
this.hour = hour;
this.minute = minute;
this.duration = duration;
this.desc = desc;
this.loc = loc;
}
public void setYear(int y){
year = y;
}
public getYear(){
return year;
}
public void setMonth(int m){
month = m;
}
public getMonth(){
return month;
}
public void setDayOfMonth(int dom){
dayOfMonth = dom;
}
public getDayOfMonth(){
return dayOfMonth;
}
public void setHour(int hr){
hour = h;
}
public getHour(){
return hour;
}
public void setMinute(int min){
minute = min;
}
public getMinute(){
return minute;
}
public void setDuration(int d){
duration = d;
}
public getDuration(){
return duration;
}
public void setDesc(String dsc){
desc = dsc;
}
public String getDesc(){
return desc;
}
public void setLoc(String l){
loc = l;
}
public String getLoc(){
return loc;
}
}
//Appointment class
class Appointment extends Event {
ArrayList<String> attendees;
public Appointment() {
super();
attendees = new ArrayList<String>();
}
public Appointment(int year, int month, int dayOfMonth, int hour, int minute, int duration, String desc, ArrayList<String> attendees) {
super(year, month, dayOfMonth, hour, minute, duration, desc);
this.attendees = attendees;
}
public void addAttendees(String person){
attendees.add(person);
}
public ArrayList<String> getAttendees(){
return attendees;
}
}



