Question

In: Computer Science

This code must be written in Java. This code also needs to include a package and...

This code must be written in Java. This code also needs to include a package and a public static void main(String[] args)

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. Apply Exception Handling.

Solutions

Expert Solution

Java code :

import java.util.*;
class Day_of_week {
   static void finding_the_week(int day_value, int month_value, int year_value){
       if (month_value == 1) {
           month_value = 13;
           year_value--;
       }
       if (month_value == 2){
           month_value = 14;
           year_value--;
       }
       int q = day_value;
       int m = month_value;
       int K = year_value % 100;
       int J = year_value / 100;
       int h = (q + 26*(m + 1) / 10 + K + K / 4 + J / 4 + 5*J) % 7;
       switch (h)
       {
           case 0 : System.out.println("Day of the week is Saturday"); break;
           case 1 : System.out.println("Day of the week is Sunday"); break;
           case 2 : System.out.println("Day of the week is Monday"); break;
           case 3 : System.out.println("Day of the week is Tuesdau"); break;
           case 4 : System.out.println("Day of the week is Wednesday"); break;
           case 5 : System.out.println("Day of the week is Thursday"); break;
           case 6 : System.out.println("Day of the week is Friday"); break;
       }
   }
  
   public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
       int day,month,year;
       System.out.print("Enter day :");
       day = sc.nextInt();
       System.out.print("Enter month :");
       month = sc.nextInt();
       System.out.print("Enter Year :");
       year = sc.nextInt();
       finding_the_week(day,month,year);
   }
}

Output :

please up vote.If any doubts comment below.Thank you


Related Solutions

Must be written in JAVA Code Modify the program you created in previous project to accomplish...
Must be written in JAVA Code Modify the program you created in previous project to accomplish the following: Support the storing of additional user information: street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' Store the data in an ArrayList object Program to Modify import java.util.ArrayList; import java.util.Scanner; public class Address { String firstname; String lastname; int zipcode;    Address(String firstname,String...
Must be written in JAVA Code Write a program that takes a whole number input from...
Must be written in JAVA Code Write a program that takes a whole number input from a user and determines whether it’s prime. If the number is not prime, display its unique prime factors. Remember that a prime number’s factors are only 1 and the prime number itself. Every number that’s not prime has a unique prime factorization. For example, consider the number 54. The prime factors of 54 are 2, 3, 3 and 3. When the values are multiplied...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public TreeNode searchBST(TreeNode root, int val) {    }...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: TreeNode* sortedArrayToBST(vector<int>& nums) {    } }; Given an array where elements are sorted in...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: vector<int> inorderTraversal(TreeNode* root) {    } }; Given the root of a binary tree, return...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary...
Code using JAVA: must include "Main Method" for IDE testing! /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: vector<int> preorderTraversal(TreeNode* root) {    } }; Given the root of a binary tree, return...
Code using JAVA: must include a "Main Method" to run on "intelliJ". Hint: Use a hash...
Code using JAVA: must include a "Main Method" to run on "intelliJ". Hint: Use a hash table. You can use either Java HashTable or Java HashMap. Refer to Java API for the subtle differences between HashTable and HashMap. Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each...
Code using JAVA: must include a "Main Method" to run on "intelliJ". Hint: Use recursion "...
Code using JAVA: must include a "Main Method" to run on "intelliJ". Hint: Use recursion " /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public boolean isSymmetric(TreeNode...
This code has to be in java (I code in eclipse). Also these instructions have to...
This code has to be in java (I code in eclipse). Also these instructions have to be followed exactly because if not my output won't match the expected out ( this will be uploaded on zybooks). Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages: If the user is 1 year...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT