Class Date

java.lang.Object
  extended by Date

public class Date
extends java.lang.Object

Objects of the Date class represent calendar dates such as March 14, 1997.

Class invariant: No Date object will ever represent an invalid date, such as one with a negative month or day, or one whose day exceeds the number of days in its month.

Version:
1.0
Author:
Marty Stepp

Constructor Summary
Date()
          Constructs a new object representing today's date.
Date(int year, int month, int day)
          Constructs a new object representing the given year, month, and day.
 
Method Summary
 void addDays(int days)
          Adds the given number of days to this Date.
 boolean equals(java.lang.Object o)
          Returns whether o refers to a Date object representing the same year, month, and day as this one.
 int getDay()
          Returns the day represented by this Date object.
 java.lang.String getDayOfWeek()
          Returns a string such as "Monday" representing what day of the week this Date fell on.
 int getDaysInMonth()
          Returns the number of days in the month represented by the current Date.
 int getMonth()
          Returns the month represented by this Date object.
 int getYear()
          Returns the year represented by this Date object.
 boolean isLeapYear()
          Returns whether this Date falls on a leap year.
 void nextDay()
          Advances this Date to the next day.
 void subtractWeeks(int weeks)
          TODO: add this method
 java.lang.String toString()
          Returns a String representation of this Date.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Date

public Date(int year,
            int month,
            int day)
Constructs a new object representing the given year, month, and day.

Throws:
java.lang.IllegalArgumentException - if month is not between 1 and 12, or if day is not between 1 and the number of days in that month.

Date

public Date()
Constructs a new object representing today's date.

Method Detail

addDays

public void addDays(int days)
Adds the given number of days to this Date.

Throws:
java.lang.IllegalArgumentException - if days < 0.

equals

public boolean equals(java.lang.Object o)
Returns whether o refers to a Date object representing the same year, month, and day as this one.

Overrides:
equals in class java.lang.Object

getDay

public int getDay()
Returns the day represented by this Date object.

Returns:
the day, between 1 and the number of days in this Date's month (which varies from 28 to 31)

getDaysInMonth

public int getDaysInMonth()
Returns the number of days in the month represented by the current Date.


getDayOfWeek

public java.lang.String getDayOfWeek()
Returns a string such as "Monday" representing what day of the week this Date fell on.

Returns:
the day as either "Sunday", "Monday", "Tuesday, "Wednesday", "Thursday", "Friday", or "Saturday"

getMonth

public int getMonth()
Returns the month represented by this Date object.

Returns:
the month, between 1 and 12

getYear

public int getYear()
Returns the year represented by this Date object.

Returns:
the year

isLeapYear

public boolean isLeapYear()
Returns whether this Date falls on a leap year.

Returns:
true if in a year divisible by 4 but not by 100 unless by 400

nextDay

public void nextDay()
Advances this Date to the next day. If necessary, wraps to the next month and/or year.


subtractWeeks

public void subtractWeeks(int weeks)
TODO: add this method


toString

public java.lang.String toString()
Returns a String representation of this Date.

Overrides:
toString in class java.lang.Object
Returns:
a String such as "2007/7/26" for July 26, 2007