- 1

How to create a class?

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) Please help me on how to create a class. The main.java file is created below: https://code.sololearn.com/cA17A66A1077

18th Jul 2021, 5:15 AM
Eka
Eka - avatar
3 Antworten
+ 1
https://www.sololearn.com/learning/2155/
18th Jul 2021, 5:43 AM
David Akhihiero
David Akhihiero - avatar
+ 1
Eka Read problem step by step and do according to that. Here is some steps: 1 - make a Class 2 - create 3 private instance variable 3 - make a default constructor and set date in that 3 variable 4 - make a overloaded constructor with arguments day, month, year 5 - make getter and setter method of that 3 variable 6 - make a method toString() if applicable 7 - create an Enum day where you have to define days like MON, TUE, WED..…. now do all other steps as per requirement
18th Jul 2021, 5:45 AM
A͢J
A͢J - avatar
0
public class Date { }
18th Jul 2021, 6:14 AM
zemiak