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: 3902815 • 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

public class Date { private int year, month, day; public Date(int year, int month, int day) { this.year = year; this.month = month; this.day = day; } public Date() { year = 1970; month = 1; day = 1; } @Override public String toString() { return String.format("%d/%d/%d", month, day, year); } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public int getMonth() { return month; } public void setMonth(int month) { this.month = month; } public int getDay() { return day; } public void setDay(int day) { this.day = day; } }

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