Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 2 : Zeller's Algorithm Suggested Logic: ? ( ( ) ) Display a Title Get the month from the user Validate the month Get

Project 2: Zeller's Algorithm Suggested Logic: ?(())
Display a Title
Get the month from the user
Validate the month
Get the day from the user
Validate the day
Get the year from the user
Calculate the day of the week
Convert M (month) to the correct value and changing the year is necessary
Convert the year to C and D
After setting up the values for M, K, C, and D, use Java operators to apply the formula
Get the value of G
Display the day of the week using a switch statement:
G is the day of the week where:
0= Sunday ,1= Monday
2= Tuesday
3= Wednesday
4= Thursday
5= Friday
6= Saturday Any other value: Display an error message.
Display the number of entries made by the user
Testing:
Test your final program for these values plus others including your own birth date:
Here is a sample output of this project:Enter month ( or 0 to exit): 9Enter year: 2003Enter month ( or 0 to exit): 2Enter year: 2014Enter month ( or 0 to exit):0
Number of entries =} You should do this project in small steps. Please do not try to do everything at once...
Here is a possible plan:
Code and test the display of the Title
Then, ask the user to enter the month.
Set up the while loop with sentinel value (month 0)
Ask the user to enter the day and year
Add the counter
Display the counter ???
After the above code works (make sure that the user can enter several set of data, and exit with month =0)
Add the validations for month and day
Add the if and calculations statements for G
Display the value of G (once you got the value right, then delete this statement)
Display the corresponding day of the week.
Skills demonstrated in this assignment
Comments (Chapter 1)
Constants and variables (Chapter 2)
Order of operations (Chapter 2)
Calculations (Chapter 2)
Operators (Chapter 2)
Reading input data (Chapter 2)
Importing Java Packages (Chapter 3)
If statements (Chapter 4)
Switch Statements (Chapter 4)
While loops (Chapter 4)
Grading
Comments and variable names (5 pts)
While with Sentinel Value (8 pts)
Error Checking for month (5 pts)
Error Checking for day (5 pts)
Calculation of Zeller's Algorithm (20 pts)
Calculation of M (4 pts)
Calculation of C (3 pts)
Calculation of D (3 pts)
Calculation of G (10 pts)
Determination of the day of the Week (7 pts)
Counting the number of entries (5 pts)
(Zeller.java)
Write a Java program for Zeller's Algorithm, which can be used to determine the day of the week for any date
in the past, present, or future.
The program should request the user to enter the date values (month, day, and year). Next, the program should
apply the algorithm (see below), and display the appropriate day of the week. The program should loop until the
user enters 0 for a month. Use the pre-test while loop with a sentinel-value structure. See Listing 4.6 from
the textbook for an example of this type of structure. Do not use any exit, break, or boolean variable.
In addition, validate that the month is between 0 and 12, and that day is between 1 and 31. Use the while loop
structure for error checking. Do not use any other method or algorithm to solve this problem. See listing 4.7
for an example of this type of loop.
Algorithm:
The formula is:
G=([2.6M-.2]+K+D+[D4]+[C4]-2C)mod7
where:
M: is the month number
K : is the day of the month
C : is the century number
D : is the year number
explanations:
M: March is considered month 1 and February is considered month 12. Therefore,
January and February are considered to be part of the previous year.
C: Is the first two digits of the year
D: Is the last two digits of the year
G : If this value is less than 0, add a value of 7 to G
You need to cast the following expression as an integer: [2.6 M-.2]
examples:
code in java, dont uses booleans, break statements and exit breaks or exit statements and dont use print f statments and also test the code.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions