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

Write a class called Date that represents a date consisting of a year, month, an

ID: 3902990 • Letter: W

Question

Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods:

// Constructs a new Date object to represent the given date.

public Date(int y, int m, int d)

// Constructs a Date object with year 1970, month 1 (January), and day 1.

public Date()

// Returns a String representation of the Date object such as: “7/22/1970”

public String toString()

// Include accessor and mutator methods for all of the fields.

Write in Java and a at a simple level

Explanation / Answer

Date.java

public class Date {

private int day, month, year;

public Date(int y, int m, int d) {

year = y;

month = m;

day = d;

}

public Date() {

year = 1970;

month = 1;

day = 1;

}

public String toString() {

return month+"/"+day+"/"+year;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote