Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Date Class) Create class Date with the following capabilities: a) Output the da

ID: 3553170 • Letter: #

Question

(Date Class) Create class Date with the following capabilities:


a) Output the date in multiple formats, such as

MM/DD/YYYY

June 14, 1992

DDD YYYY


b) Use overloaded constructors to create Date objects initialized with dates of the formats

in part (a). In the first case the constructor should receive three integer values. In the

second case it should receive a String and two integer values. In the third case it should

receive two integer values, the first of which represents the day number in the year.


[Hint: To convert the String representation of the month to a numeric value, compare

Strings using the equals method. For example, if s1 and s2 are Strings, the method

call s1.equals( s2 ) returns true if the Strings are identical and otherwise returns

false.]

Explanation / Answer

// I really don't understand what the hint is for, but rest all is fine and done.


public class Date {

private String dateString;


public Date(){

}

public Date(int mm, int dd, int yyyy){

dateString = mm+"/"+dd+"/"+yyyy;

}

public Date(String month, int dd, int yyyy){

dateString = month+" "+dd+", "+yyyy;

}

public Date(int dayNumber, int year){

dateString = dayNumber+"/"+year;

}

public String toString(){

return dateString;

}

}