0

Date (encapsulation)|| Debugging

Create a new file called Date.java and construct a Date class that models a calendar date with day, month, and year. It contains the following members: -3 private integer instance variables: day, month (1 - 12), and year (4-digit). -a default constructor which will set the date to 01/01/1972. When called, this also prints the string "Default Constructor". -an overloaded constructor that takes in the day, month, and year as arguments. When called, this also prints the string "Overloaded Constructor". -public getters and setters for the private instance variables. -public void setDate(int day, int month, int year) - sets the day, month, and year based on the arguments. -public String toString() - returns "DD/MM/YYYY", with leading zero for DD and MM if applicable (note: return the string and do not display it from the method itself). -public Day dayOfTheWeek() - returns the day of the week (MON, TUE, WED, THU, FRI, SAT, SUN) for the date. Create an enum Day to handle this. Follow the formula below for this. To get the day of the week, one can make use of the JD (Julian Day). Based on the given date, Y M D, perform the following computations: -If the month is January or February, subtract 1 from the year to get a new Y and add 12 to the month to get a new M. Dropping the fractional part of all results of all multiplications and divisions, let: A = Y / 100 B = A / 4 C = 2 - A + B E = 365.25 x (Y + 4716) F = 30.6001 x (M + 1) JD = C + D + E + F - 1524.5 The day of the week is JD % 7 (notice that JD ends in .5. Investigate this properly to get the correct day of the week). I don't understand why my code is not running. Please help me. https://code.sololearn.com/cA4A13a18A19

18th Jul 2021, 11:54 PM
Eka
Eka - avatar
1 ответ
0
it is Sololearn bug, move enum Day{...} to the end of source code
20th Jul 2021, 5:14 AM
zemiak