Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a static method with input parameters month, day, and year that returns the day of the week in Java. The header should look like

Write a static method with input parameters month, day, and year that returns the day of the week in Java. The header should look like this:

public static String dayOfWeek(int month, int day, int year)

Use a Calendar class object to find the day of the week. This object must be defined in the dayOfWeek method, not in the main method. Also please write comments throughout or points will be taken off.

Important: don't use any date and/or time classes for this project other than Calendar. For example, don't use the SimpleDateFormat class. 50% deduction if you use date and/or time classes other than Calendar.

Some tricky points about the Calendar class:

  1. A constructor is not used to instantiate a Calendar object. Use the static getInstance method instead:

    • Calendar cal = Calendar.getInstance( );

  2. Use the Calendar instance method set to set the month, day, and year of your Calendar object, using the parameters passed in from the dayOfWeekmethod. Caution: the set method accepts its parameters in a different order than your getDayOfWeek method.

  3. The int values representing the month are zero-based (0 means January, 1 means February, ... , 11 means December), but the days of the week are one-based (1 means Sunday, 2 means Monday, ..., 7 means Saturday).

  4. Use the Calendar get method to get the day of week from the Calendar object.

The dayOfWeek method returns a String object. However, the Calendar object returns a zero-based int. Use this array in your dayOfWeek method to translate:

  1. String[ ] dayNames = {"", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

Write three test classes:

  1. A traditional test class named Test1 with a main method that tests your getDayOfWeek method using hardcoded parameters. Check at least five dates, including your birth date.

  2. A JUnit test class named Test2 that tests the same dates that you tested in your traditional Test1 class.

  3. An interactive class named Test3 that repeatedly prompts the user for a date and prints the corresponding day of week name, for example:

  4. 1/17/2019 Day of week is Thursday. 1/1/2019 Day of week is Tuesday.

  5. Use a blank line to terminate your input, or use Control-Z for Windows, Control-D for Unix. See the SumOfProducts Example to see various ways of terminating an input loop.

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

Step: 3

blur-text-image

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions