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

Please create a program for the Date class that satisfies these requirements in:

ID: 3717709 • Letter: P

Question

Please create a program for the Date class that satisfies these requirements in: JAVA

Please use many comments and read the task thoroughly.

Full points will be awarded, thanks in advance!

Class Date: The date class represents a date in our world. Do not use any built in date classes in this assignment All days days should be between [1-31] Each month should be between [1-12] Each month has exactly 31 davs All years should be between [2014 -2024] Entering an invalid date should print an error message to the console, and the program should immediately exit . . The Savitch book talks about an implemtation for dates that is similar but not exactly ) like what we are describing here Date Methods: Date ( int month, int day, int year) o Constructor Date (Date other) o Copy Constructor int getYear(; int getMonth(); int getDay(); void setYear int year); void setMonth( int month); void setDay( int day); boolean isAfter( Date compareTo) . o Return true if the compareTodate is after the date boolean equals( Object date)

Explanation / Answer

public class Date { private int month; private int day; private int year; public Date(int month, int day, int year) { setMonth(month); setDay(day); setYear(year); } public Date(Date other) { this.month = other.month; this.day = other.day; this.year = other.year; } public int getMonth() { return month; } public void setMonth(int month) { if(month < 1 || month > 12) { System.out.println("Invalid month"); System.exit(-1); } this.month = month; } public int getDay() { return day; } public void setDay(int day) { if(day < 1 || day > 31) { System.out.println("Invalid day"); System.exit(-1); } this.day = day; } public int getYear() { return year; } public void setYear(int year) { if(year < 2014 || month > 2024) { System.out.println("Invalid year"); System.exit(-1); } this.year = year; } public boolean isAfter(Date compareTo) { int cmp = Integer.compare(compareTo.year, year); if(cmp == 0) { cmp = Integer.compare(compareTo.month, month); if(cmp == 0) { cmp = Integer.compare(compareTo.day, day); return cmp < 0; } else { return cmp < 0; } } else { return cmp < 0; } } public boolean equals(Object date) { Date other = (Date) date; return year == other.year && month == other.month && day == other.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