Question
This is in Java Design a User-Defined class called SimpleDate.java with three attributes day, month and year. A date object represents a date according to
This is in Java
Design a User-Defined class called SimpleDate.java with three attributes day, month and year. A date object represents a date according to the Gregorian calendar. The class should provide the following:
Default and parametric constructors.
getMonth( ), getDay( ), getYear( ) methods.
setYear( )
setMonth( ) check if the month value is between 1 12 before assigning to month
setDay( ) this method will check the month first to validate whether the value that will be assigned to day is legal. Example, a value of 31 for the day for month 11 (November) is invalid and should not be assigned and should throw an IllegalArgumentException as shown below: throw new IllegalArgumentException( appropriate error message should go here ); If the year is a leap year than a value of 29 for the day and a value of 2 for the month(February) is valid. To determine whether a year is a leap year, use the GregorianCalendar class that is part of the util package. This class has a non-static method called isLeapYear( ).
Implement toString( ) and equals( ) method.
Make sure to keep make your output verbose and comment your code.
Next, create a client program SimpleDateTest.java with the main method( ). In the program prompt the user for a day, month, and year to create a Date object and display date values using the get methods and demonstrate the working of the set methods. Create at least 5 appropriate test cases to test the set methods of the Date class. Use the below format for Test Cases:
Test Case | Inputs | Expected Output | Actual Output |
1 | Year = 2012 Month = 2 Day = 28 to the constructor followed by call to the toString( ) method | 2/28/2012 |
|
2 | Year = 2013 Month = 3 Day = 32 to the constructor followed by call to the toString( ) method | IllegalArgumentException generated with the message Day value cannot be greater than 31 |
|
Thanks for the help.
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