Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a. Construct a Date class function named isWeekday() that returns a Boolean valu

ID: 3882549 • Letter: A

Question

a. Construct a Date class function named isWeekday() that returns a Boolean
value of true if the date is a weekday; otherwise, it should return a false value. The function
should call the dayOfWeek() function written for Exercise 5a, and then use the returned integer value to determine whether the day is a weekday. A weekday is any day from 2 to 6, which
corresponds to the days Monday through Friday.
b. Include the function written for Exercise 6a in a complete program. For testing purposes,
use the fact that March 12, 2011, was a Saturday and March 15, 2011, was a Tuesday

Explanation / Answer

Date.java

package Test9;

import java.util.Calendar;

public class Date {

public static void main(String[] args) {

System.out.println("Weekend today: "+isWeekday());

}

public static int dayOfWeek() {

Calendar calendar = Calendar.getInstance();

int day = calendar.get(Calendar.DAY_OF_WEEK);

return day+1;

}

public static boolean isWeekday() {

int day = dayOfWeek();

if(day >=2 && day <=6) {

return true;

} else {

return false;

}

}

}

Output:

Weekend today: true

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote