Skip to main content

Independent Task: Create Event

Now you have created Activity without any regressions, you can create the Event class as a second child class of Activity.

Callout Box Icon

Learning Outcomes

  • Create a new class that extends and existing class
  • Implement abstract methods
  • Run unit tests
Reminder: Eclipse Java Class Creation

Implement Event Class

Create a new Java class called Event in the edu.ncsu.csc216.wolf_scheduler.course package of the WolfScheduler project. Select the following options:

  • Browse for Activity as the Superclass
  • Check the option to creating stubs for “Inherited abstract methods”.
  • Check the option to “Generate comments”.


Figure: Create Event Class
Figure: Create Event Class


Implement Event State

The Event class will not yet compile because we do not yet call Activity’s constructor. Before creating a constructor for Event, we want to implement the field for Event. This way we can integrated the field when generating our constructor.

Event knows about one other item in addition to those provided by Activity:

  • a String called eventDetails.

The field should be private.

Generate the getter and setter for the field.

Implement Event() Constructor

Generate an Event() Constructor using Event’s fields.


Figure: Generate Event Constructor
Figure: Generate Event Constructor


The constructor should have five parameters (title, meetingDays, startTime, endTime, and eventDetails). This is because the Event constructor also needs the parameters to construct the parent Activity. Update the lines that set the fields to call the corresponding setter methods as a common path of error checking.

1
2
3
4
    public Event(String title, String meetingDays, int startTime, int endTime, String eventDetails) {
        super(title, meetingDays, startTime, endTime);
        setEventDetails(eventDetails);
    }

Implement Event.setEventDetails()

The setEventDetails() method should throw an IllegalArgumentException if the eventDetails parameter is null. Since eventDetails are optional, the field may contain an empty string. The IllegalArgumentException message should be “Invalid event details”.

Implement Event.getShortDisplayArray()

The getShortDisplayArray() should return a String array of length four. The first two values should be empty strings since Event doesn’t have a name or section. The last two values should be the title and the meeting string.

Implement Event.getLongDisplayArray()

The getLongDisplayArray() should return a String array of length seven. The first two values should be empty strings since Event doesn’t have a name or section. The third value is the title followed by two values with empty strings. The last two are the meeting string and eventDetails.

Override toString()

Right click in the editor and select Source > Override/Implement Methods. Check the boxes to override toString() (which is under Object).


Figure: Override Methods
Figure: Override Methods


Implement toString() to produce a comma separated string that meets the description in [UC 10].

Overriding Other Methods?

You don’t need to override the equals() and hashCode(). An Event should be considered the same if the title and the meeting information is the same; the details aren’t needed for equality. Therefore, you don’t need to override these methods. Event inherits Activity’s equals() and hashCode() methods.

Test Event

We have provided tests for Event.

Add EventTest to the test folder in the edu.ncsu.csc216.wolf_scheduler.course package.

Oh no! Two failing tests!

  • testSetMeetingDaysAndTimeInvalid() has a failing test with the meeting days string of “A”. Unlike Courses, Events cannot have a meeting day string of “A”.
  • testSetMeetingDaysAndTimeValid() has a failing test with the meeting days string of “UMTWF”. The characters ‘S’ and ‘U’ are valid for Events; they can occur on Saturdays or Sundays.

You will eventually correct the code causing that error in the Debugging section, which comes next.

All of your other tests should pass now, however. If they do not, you will need to debug those tests. It may be helpful to hold on fixing them until after we discuss the debugger.

Comment Event and Fix Static Analysis Notifications

Complete the following tasks:

  • Update all your Javadoc for Event. Overridden methods much also be commented to describe the specifics in the overridden implementation. Note that Checkstyle will NOT generate notifications if you’re missing comments on overriden methods. But we do check for that when grading!
  • Resolve all static analysis notifications.
Reference: Staging and Pushing to GitHub

Check Your Progress

Complete the following tasks before pushing your work to GitHub.

  • Make sure that all fields, methods, and constructors are commented.
  • Resolve all static analysis notifications.
  • Fix test failures.
  • Commit and push your code changes with a meaningful commit message. Label your commit with “[Implementation]” for future you!