Answered step by step
Verified Expert Solution
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 : 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:
Sunday Monday
Tuesday
Wednesday
Thursday
Friday
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 to exit: Enter year: Enter month or to exit: Enter year: Enter month or to exit:
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
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
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
Constants and variables Chapter
Order of operations Chapter
Calculations Chapter
Operators Chapter
Reading input data Chapter
Importing Java Packages Chapter
If statements Chapter
Switch Statements Chapter
While loops Chapter
Grading
Comments and variable names pts
While with Sentinel Value pts
Error Checking for month pts
Error Checking for day pts
Calculation of Zeller's Algorithm pts
Calculation of M pts
Calculation of C pts
Calculation of D pts
Calculation of G pts
Determination of the day of the Week pts
Counting the number of entries pts
Zellerjava
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 for a month. Use the pretest while loop with a sentinelvalue structure. See Listing 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 and and that day is between and Use the while loop
structure for error checking. Do not use any other method or algorithm to solve this problem. See listing
for an example of this type of loop.
Algorithm:
The formula is:
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 and February is considered month 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 add a value of to G
You need to cast the following expression as an integer: M
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.
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