, , ,

Course: Berkeley’s CS 61B: Data Structures.

Homework 2

Homework 2 (mirror) is due before lecture 6.

One problem about Date manipulations.

[…] Your task is to fill in the implementation of a class that manipulates dates. Do not use any of the built-in operations on dates provided in the Java library in your solution. […]

The interesting part was making difference() — a function method that calculates the difference of two Date objects — work correctly. That took me some trial and error (and a re-imagining/re-write) to get right.

Interesting how a simple thing like that made me pause, I’ve used ready-made libraries in the past (perl’s and PHP’s DateTime) and didn’t have to deal with these issues directly.

Date.java (view | download)