Skip to content

Commit

Permalink
HW2 Done
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Oct 30, 2020
1 parent 18ced27 commit 2a5c4ef
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions hw2/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ public static boolean isLeapYear(int year) {
public static int daysInMonth(int month, int year) {
switch (month) {
case 2:
if (isLeapYear(year)) return 29;
else return 28;
if (isLeapYear(year)) {
return 29;
} else {
return 28;
}
case 4:
case 6:
case 9:
Expand All @@ -86,7 +89,12 @@ public static int daysInMonth(int month, int year) {
* Years prior to A.D. 1 are NOT valid.
*/
public static boolean isValidDate(int month, int day, int year) {
return year >= 1 && year <= 9999 && month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth(month, year);
if ((year >= 1 && year <= 9999) && (month >= 1 && month <= 12) && (day >= 1 && day <= daysInMonth(month, year))) {
return true;
} else {
return false;
}

}

/** Returns a string representation of this date in the form month/day/year.
Expand All @@ -102,20 +110,22 @@ public String toString() {
* @return true if and only if this Date is before d.
*/
public boolean isBefore(Date d) {
// return true; // replace this line with your solution
if (this.difference(d) < 0) {
return true;
} else return false;
} else {
return false;
}
}

/** Determines whether this Date is after the Date d.
* @return true if and only if this Date is after d.
*/
public boolean isAfter(Date d) {
// return true; // replace this line with your solution
if (this.difference(d) > 0) {
return true;
} else return false;
} else {
return false;
}
}

/** Returns the number of this Date in the year.
Expand Down

0 comments on commit 2a5c4ef

Please sign in to comment.