July 12

July 11 July 15

Homework / Assignment 3

This project is due next Tuesday, although you can of course submit it any time! If you want feedback or help from me before grading, please submit whatever you have to me by Sunday at 6pm. (I will also respond to early queries if I can.)

The goal is to practice

  • using data structures
  • using “wrapper” classes for primitive data types
  • consulting the  Java 8 API
  • using new Javadoc @ annotations
  • using code completion (optional; up to you).

You will write a BlueJ project creating a class “Month” that keeps track of the holidays in a month using a HashMap. (This is probably not a great way to do it, but, hey, this is an exercise.) You will do this in a similar fashion to the Deli FIFO Queue I demonstrated in class.

Store the information in the following class property:

private HashMap<Integer,String> holidays = new HashMap<Integer,String>();

Notice that you cannot use int; you must use the wrapper class Integer. It’s not hard to use, but don’t forget to use new with the constructor (I did). Refer to the Java 8 API for information about HashMap and Integer. Don’t forget to not panic.

Creating an Integer instance:

int i = 42;
Integer myInt = new Integer(i):

Please do your best to use Javadoc comments as I demonstrated in class. You will need only these:

  • @author
  • @version
  • @param
  • @return

But feel free to do more if this interests you:  How to Write Doc Comments

Method specifications

public void addHoliday​(int day, String holiday)
Add a holiday to the month (we assume no more than one per day).
day – day of the month
holiday – String description
public boolean isHoliday​(int day)
Check whether there is a holiday on this day.
day – day of the month
true if so, false otherwise
public String holidayOn​(int day)
Return the holiday for this day.
day – day of the month
description of the holiday
public int numberOfHolidays()
How many holidays in this month?
number of holidays