|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Creating a days ,month and year ranges and leap year
Here is the question:
In this practical we will be examining the Doomsday algorithm… one of the simpler algorithms for mapping an arbitrary date onto a day of the week. For the purposes of this practical we will be working in the Gregorian calendar (the dominant modern calendar since 1582). This practical need only function between the years 1800 and 2100 This algorithm exploits the fact that certain dates always occur on the same day of the week in any given year. The algorithm has three phases, finding the century’s anchor year, finding the year’s doomsday and finding the day of the week. 1. Create a file Doomsday.java containing a Doomsday class with a set of java constants for each day of the week, from MONDAY = 0 till SUNDAY = 6 2. The class must contain private members for the Year, Month & Day in question, these members must be set in the class’ constructor 3. The class must contain a predicate (boolean returning) method isLeap() to determine if the year is a leap year. 4. The function getAnchorDay() maps the following date ranges onto days respectively. 1800-1899->Friday, 1900-1999->Wednesday, 2000- 2099->Tuesday, 2100-2199->Sunday, 5. The method getDoomsdayDate() returns an integer representing the date in the month on which doomsday will fall. These doomsdays are as follows: Jan – 3 (or 4 if leap year), Feb – 28 (or 29 if leap year) March – 0 (last day in February), April – 4, May – 9, June - 6 July – 11, August – 8, September – 5, October – 10, November - 7 December – 12 6. The method getDoomsday() calculates the doomsday as follows y <-last 2 digits of year a <-y/12] b <-y mod 12 c <-[b 4] d <-a +b +c diff <-DAY - DOOMSDAYDATE DOOMSDAY <-(d +diff +ANCHORDAY) mod 7 Ensure DOOMSDAY is in the range 0-6 7. Write a method to convert the Doomsday number to a string 8. Write a driver class to capture the year, month & day via a Scanner instance and demonstrate the Doomsday class’ functionality. THIS IS HOW I STARTED IT i DON'T KNOW TO PROCEED public class Doomsday { public static final int Monday = 0; public static final int Tuesday = 1; public static final int Wednesday= 2; public static final int Thursday = 3; public static final int Friday = 4; public static final int Saturday = 5; public static final int Sunday = 6; public int Year(){} public int Month() {} // the private memebers public int Day() {} public int getAnchorDay() for (day;day==1800-1899;day++){ return Friday; } for (day;day==1900-1999;day++){ return Wednasday; } for (day;day==2000-2099;day++){ return Tuesday; } for (day;day==2100-2199;day++){ return Sunday; } publlic getDoomsdayDate() Jan – 3 (or 4 if leap year), Feb – 28 (or 29 if leap year) March – 0 (last day in February), April – 4, May – 9, June - 6 July – 11, August – 8, September – 5, October – 10, November - 7 December – 12 I dont know how to do this one ? public getDoomsday() I din't know how to do this one ? |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Creating a days ,month and year ranges and leap year |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|