Question
Write a Java Program in BlueJ: File newDateExample.zip (3.68 KB) [ /** * Class to store a date as three intgers: day, month and year.
Write a Java Program in BlueJ: File newDateExample.zip (3.68 KB)
[
/** * Class to store a date as three intgers: day, month and year. * * @author * @version */ public class Date { // instance variables - replace the example below with your own private int day; private int month; private int year;
/** * Constructor for objects of class Date to intitialize each member to 0 */ public Date() { // initializee instance variables } /** * Constructor for objects of class Date to intitialize each member to the specified parameters * @param day the value to which the day field will be set * @param month the value to which the month field will be set * @param year the value to which the year field will be set */ public Date(int day, int month, int year) { // initialize instance variables } /** * method to set the Date to the specified parameters * * @param d the value to which the day field will be set * @param m the value to which the month field will be set * @param y the value to which the year field will be set */ public void setDate(int d, int m, int y) { if (isValidMonth(m)) { if (isValidDay(d,m,y)) { day = d; month = m; year = y; } else { System.out.println("The day " + d + " is not valid for the month " + m); System.out.println("The date has not been changed"); } } else { System.out.println("The month must be an integer from 1 to 12"); System.out.println("The date has not been changed"); } } /** * method to determine if two Date objects are equal * * @param theDate: the Date object to compare * @return true if this date is equal to theDate and false otherwise */ public boolean equals(Date theDate) { return ((day == theDate.day) && (month == theDate.month) && (year == theDate.year)); } /** * method to determine if one Date object is less than another * * @param theDate: the Date object to compare * @return true if this date is less than theDate and false otherwise */ public boolean lessThan(Date theDate) { return true; } /** * method to determine if two Date objects are not equal * * @param theDate: the Date object to compare * @return true if this date is not equal to theDate and false otherwise */ public boolean notEquals(Date theDate) { return (!(this.equals(theDate))); } /** * method to determine if one date object is greater than or equal to another * * @param theDate: the Date object to compare * @return true if this date is greater than or equal to theDate and false otherwise */ public boolean greaterThanOrEqual(Date theDate) { return true; } /** * method to determine if one Date object is greater than another * * @param theDate: the Date object to compare * @return true if this date is greater than theDate and false otherwise */ public boolean greaterThan(Date theDate) { return true; } /** * method to determine if one date object is less than or equal to another * * @param theDate: the Date object to compare * @return true if this date is less than or equal to theDate and false otherwise */ public boolean lessThanOrEqual(Date theDate) { return true; } /** * method to determine if a given month value is a valid value (1-12) * * @param theMonth: the value supplied for the month * @return true if the month is an integer from 1 to 12 */ private boolean isValidMonth(int theMonth) { return true; } /** * method to determine if a given day value is a valid value (1-12) * * @param theday: the value supplied for the day * @param theMonth: the value supplied for the month * @return true if the day is a valid integer for the given month */ private boolean isValidDay(int theDay,int theMonth, int theYear) { return true; } }
]
Complete the Date class (provided in the newDateExample project provided as follows: The Date() constructor is completed. You do not need to modify. Modify the Date(int day, int month, int year) so that it works as explained in the comments. You will need to use the this keyword. The setDate method is completed. The equals method is completed. Complete the lessThan method so that it checks to see if one Date object is less than another. Here you must compare the dates using their fields. The notEquals method is completed. Complete the greaterThan, greaterThanOrEqual, and lessThanOrEqual methods by making internal method calls only. You may not compare any fields directly (See the notEquals method). Complete the isValidMonth method so that it returns true if the month provided is an integer from 1 to 12. Complete the isValidDay method do that it returns true if the day is valid for the given month. For your first try, assume that February always has 28 days. Once you get the method to work, add a check so that it allows the day for February to be 29 in a leap year.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started