Question: I have a problem where I have an undeclared method in remove(); in the class calendar. How do I fix this undeclared method error. I

I have a problem where I have an undeclared method in remove(); in the class calendar. How do I fix this undeclared method error. I put the 2 classes code down below that I am working in. Also how would I implement a test case for the calendar class to make sure it functions. Just need to know how to fix the undeclared method error and implement a test case for calendar.

public class Calendar {

// declare your 2D array of events here private Event[][] events; /** * Creates a new Calendar object. */ public Calendar() { events = new Event[7][10]; }

/** * Add a new event on the specified day. The time for the event * is extracted from the event object itself. If the day is * invalid, the method does nothing. If the event is outside * the window of 8am-5pm, the method does nothing. If another * event has already been entered for the specified day/time, it * is removed and replaced by the one being added. * * @param day The day for the event (0-6). * @param event The appointment to add on that day (contains * its own time). */ public void addEvent(int day, Event event) { if (day < 0 || day >= 7 || event.getHour() < 8 || event.getHour() > 17) { return; } int hour = event.getHour() - 8; if (events[day][hour] != null) { events[day][hour].remove(); } events[day][hour] = event; }

// ---------------------------------------------------------- /** * Retrieve an existing event (if any) by day and hour. * * @param day The day to check (0-6). * @param hour The hour to check (0-23), in military time. * @return The event at the specified day and time, * if there is one, or null if no event is found, if * the day specified is invalid, or if the hour specified is * outside the range 8-17. */ public Event getEvent(int day, int hour) { if (day < 0 || day >= 7 || hour < 8 || hour > 17) { return null; } int h = hour - 8; return events[day][h]; } }

The second one is the event class im working in

public class Event { //~ Fields ................................................................

// Add a field representing the hour of this event private int hour; // Add a field representing the description of this event private String description;

//~ Constructor ...........................................................

// ---------------------------------------------------------- /** * Creates a new Event object. * * @param hour The hour (time) of this event, in military time * (0-23). * @param description The description of this event. */ public Event(int hour, String description) { this.hour = hour; this.description = description; }

//~ Methods ...............................................................

// ---------------------------------------------------------- /** * Get the description of this event. * @return This event's description. */ public String getDescription() { return description; }

// ---------------------------------------------------------- /** * Get the hour of this event. * @return This event's hour, in military time. */ public int getHour() { return hour; }

// ---------------------------------------------------------- /** * Set the description of this event. * @param newDescription The new description for this event. */ public void setDescription(String description) { this.description = description; }

// ---------------------------------------------------------- /** * Set the hour of this event. * @param newHour The new hour for this event, in military * time. */ public void setHour(int hour) { this.hour = hour; } // ---------------------------------------------------------- /** * Set the hour of this event, using a more human-friendly * string. * @param newHour The new hour for this event, using an * am/pm designation such as "9am" or "5pm". */ public void setTime(String theTime) { String digitsOnly = theTime.substring(0, theTime.length() - 2); int hour = Integer.parseInt(digitsOnly); this.hour = hour; }

// ---------------------------------------------------------- /** * Get a string representation of this event. * @return A human-readable representation of this event * that includes the time (in am/pm format) and the description, * such as "11am: CS 1114". */ @Override public String toString() { if(hour>=1 && hour<=12) { return hour+"am: "+description; } else if(hour>0) { if(hour==0) return "12am: "+description; else return (hour-12)+"pm: "+description; } else{ return "Invalid Time"; } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!