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

Please help!!! Program Specification You are to write the following PersonalCale

ID: 3840382 • Letter: P

Question

Please help!!!

Program Specification

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.

This is what I am doing

1. Event Class

public class Event {
   private int date;
   private int year;
   private int month;
   private int dayOfMonth;
   private int hour;
   private int minute;
   private String description;
   private String location;
   private int duration;
  
   public Event(){
      
   }

   public Event (int year, int month,int dayOfMonth,int hour, int minute,String des,String loc,int dur){
       this.year = year;
       this.month = month;
       this.dayOfMonth = dayOfMonth;
       this.hour = hour;
       this.minute = minute;
       this.description = des;
       this.location = loc;
       this.duration = dur;
       }
   public int getDate(){
       return date;
       }
   public int getYear(){
       return year;
       }
   public int getMonth(){
       return month;
       }
   public int getDay(){
       return dayOfMonth;
       }
   public int getHour(){
       return hour;
       }
   public int getMinute(){
       return minute;
       }
   public String getDec(){
       return description;
       }
   public String getLoc(){
       return location;
       }
   public int getDur(){
       return duration;
       }
   @Override
   public String toString(){
       String result = "";
       result = "Description " + getDec() + " Location " + getLoc();
       return result;
       }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Event other = (Event) obj;
       if (year != other.year)
           return false;
       if (month != other.month)
           return false;
       if (dayOfMonth != other.dayOfMonth)
           return false;
       if (hour != other.hour)
           return false;
       if (minute != other.minute)
           return false;
       if (month != other.month)
           return false;
       if (description == null) {
           if (other.description != null)
               return false;
       } else if (!description.equals(other.description))
           return false;
       return true;
   }


}

2. Appointment Class

import java.util.ArrayList;


public class Appointment extends Event{
   ArrayList attendees = new ArrayList();
   private int year;
   private int month;
   private int dayOfMonth;
   private int hour;
   private int minute;
   private int duration;
   private String description;
  
  
   public Appointment(){
      
   }
   public Appointment(int year, int month,int dayOfMonth,int hour, int minute,int dura, String desc){
       this.year = year;
       this.month = month;
       this.dayOfMonth = dayOfMonth;
       this.hour = hour;
       this.minute = minute;
       this.duration = dura;
       this.description = desc;
      
      
   }
   public int getYear(){
       return year;
   }
   public int getMonth(){
       return month;
   }
   public int getDayOfMonth(){
       return dayOfMonth;
   }
   public int getHour(){
       return hour;
   }
   public int getMinute(){
       return minute;
   }
   public int getDuration(){
       return duration;
   }
   public String getDescription(){
       return description;
   }
   public boolean add(String objToAdd){
       return attendees.add(objToAdd);
   }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Appointment other = (Appointment) obj;
       if (year != other.year)
           return false;
       if (month != other.month)
           return false;
       if (dayOfMonth != other.dayOfMonth)
           return false;
       if (hour != other.hour)
           return false;
       if (minute != other.minute)
           return false;
       if (month != other.month)
           return false;
       if (description == null) {
           if (other.description != null)
               return false;
       } else if (!description.equals(other.description))
           return false;
       return true;
   }

}

3. PersonalCalendar Class

import java.util.ArrayList;

public class PersonalCalendar extends ArrayList<Appointment>{
   private ArrayList<Object> app = new ArrayList<Object>();
   public PersonalCalendar(){
       app = new ArrayList<Object>();
      
   }
   public PersonalCalendar(Appointment a ,Event e){
       app.add(a);
       app.add(e);
      
      
      
   }
  
   }

4. JUnitTest

import static org.junit.Assert.*;

import org.junit.Test;
public class PersonalTest {
   @Test
   public void testZero() {
       Appointment cnt = new Appointment(1, 2, 3, 4, 5, 5, "doctor");
       Event event = new Event(2, 3, 4, 5, 6,"java","English", 10);
       String ev = (cnt.getDescription());
      
      
      
   }

}

Explanation / Answer

public class Event {
   private int date;
   private int year;
   private int month;
   private int dayOfMonth;
   private int hour;
   private int minute;
   private String description;
   private String location;
   private int duration;
  
   public Event(){
      
   }

   public Event (int year, int month,int dayOfMonth,int hour, int minute,String des,String loc,int dur){
       this.year = year;
       this.month = month;
       this.dayOfMonth = dayOfMonth;
       this.hour = hour;
       this.minute = minute;
       this.description = des;
       this.location = loc;
       this.duration = dur;
       }
   public int getDate(){
       return date;
       }
   public int getYear(){
       return year;
       }
   public int getMonth(){
       return month;
       }
   public int getDay(){
       return dayOfMonth;
       }
   public int getHour(){
       return hour;
       }
   public int getMinute(){
       return minute;
       }
   public String getDec(){
       return description;
       }
   public String getLoc(){
       return location;
       }
   public int getDur(){
       return duration;
       }
   @Override
   public String toString(){
       String result = "";
       result = "Description " + getDec() + " Location " + getLoc();
       return result;
       }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Event other = (Event) obj;
       if (year != other.year)
           return false;
       if (month != other.month)
           return false;
       if (dayOfMonth != other.dayOfMonth)
           return false;
       if (hour != other.hour)
           return false;
       if (minute != other.minute)
           return false;
       if (month != other.month)
           return false;
       if (description == null) {
           if (other.description != null)
               return false;
       } else if (!description.equals(other.description))
           return false;
       return true;
   }

}

import static org.junit.Assert.*;

import org.junit.Test;
public class PersonalTest {
   @Test
   public void testZero() {
       Appointment cnt = new Appointment(1, 2, 3, 4, 5, 5, "doctor");
       Event event = new Event(2, 3, 4, 5, 6,"java","English", 10);
       String ev = (cnt.getDescription());
   }

}