Question
Write a program named DayOfWeek that computes the day of the week for any date entered by the user. The user will be prompted to
Write a program named DayOfWeek that computes the day of the week for any date entered by the user. The user will be prompted to enter a month, day, and year. The program will then display the day of the week (Sunday..Saturday). The following example shows what the user will see on the screen: This program calculates the day of the week for any dates. Enter month (1-12): 9 Enter day (1-31): 25 Enter year: 1998 The day of the week is Friday. Hint: Use Zeller's congruence to compute the day of the week. Zeller's congruence relies on the following quantities: J is the century (19, in our example) K is the year within the century (98, in our example) m is the month (9, in our example) q is the day of the month (25, in our example) The day of the week is determined by the following formula: h = (q + 26(m + 1) / 10 + K + K / 4 + J / 4 + 5J) mod 7 where the results of the divisions are truncated. The value of h will lie between 0 (Saturday) and 6 (Friday). Note: Zeller's congruence assumes that January and February are treated as months 13 and 14 of the previous year; this affects the values of K and m, and possibly the value of J. Note that the value of h does not match the desired output of the program, so some adjustment will be necessary.
Use inheritance if possible or exception handling.
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