I need this program in JAVA: Pad 8:57 AM a virtualcampus.pupr.edu Course Content
ID: 3714184 • Letter: I
Question
I need this program in JAVA:
Pad 8:57 AM a virtualcampus.pupr.edu Course Content SP-18-CECS3210-31-SJU (ADVANCED PROGRAMMING (SP-18 SJU)) Asig2 - Day of the Week (Due 04/26) Asig2 - Rational Numbers (Due 01/27) 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 wil then display the day of the week Sunday..Saturday). The following example shows what the user will see on the screen: My Course Syllabus Professor Course Information Course Content Tools Information Resources Blackboard Support 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 - (q26(m 1)/ 10K K/4+J14 +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 necessaryExplanation / Answer
// Java program to find Find the Day
// for a Date
import java.util.*;
class GFG
{
// Print Day for a Date
static void Zellercongruence(int day, int month,int year)
{
if (month == 1)
{
month = 13;
year--;
}
if (month == 2)
{
month = 14;
year--;
}
int q = day;
int m = month;
int k = year % 100;
int j = year / 100;
int h = q + 13*(m + 1) / 5 + k + k / 4 + j / 4 + 5 * j;
h = h % 7;
switch (h)
{
case 0 : System.out.println("The day of the week is Saturday"); break;
case 1 : System.out.println("The day of the week is Sunday"); break;
case 2 : System.out.println("The day of the week is Monday"); break;
case 3 : System.out.println("The day of the week is Tuesday"); break;
case 4 : System.out.println("The day of the week is Wednesday"); break;
case 5 : System.out.println("The day of the week is Thursday"); break;
case 6 : System.out.println("The day of the week is Friday"); break;
}
}
// Driver code
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter month(1-12) :");
int month=sc.nextInt();
System.out.print("Enter day(1-31) :");
int date=sc.nextInt();
System.out.print("Enter year :");
int year=sc.nextInt();
Zellercongruence(date, month, year); //date (dd/mm/yyyy)
sc.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.