Ask Question
7 November, 18:29

You are developing a system to process lists of days of the week, represented as strings. Create a function is_weekend that consumes a list and returns whether the list has the string "Saturday" or the string "Sunday" in it. Call and print this function once with a list of days of the week.

+1
Answers (1)
  1. 7 November, 18:46
    0
    public static boolean is_weekend (List week) {

    if (week. contains ("Saturday") ||week. contains ("Sunday"))

    {

    System. out. println ("List has a weekend");

    return true;

    }

    else{

    System. out. println ("List has no weekend");

    return false;

    }

    }

    Explanation:

    Using java programming language Import java. util. ArrayList and import java. util. List; so you can implement a java list Create a list and add the days of the week Create the required method using the contains () method to check for Sunday and Saturday and return true if the list contains them See the complete program with a call to the method

    import java. util. ArrayList;

    import java. util. List;

    public class Car {

    public static void main (String[] args) {

    List daysOfWeek = new ArrayList ();

    daysOfWeek. add ("Sunday");

    daysOfWeek. add ("Moday");

    daysOfWeek. add ("Tuesday");

    daysOfWeek. add ("Wednesday");

    daysOfWeek. add ("Thursday");

    daysOfWeek. add ("Friday");

    daysOfWeek. add ("Saturday");

    is_weekend (daysOfWeek);

    }

    public static boolean is_weekend (List week) {

    if (week. contains ("Saturday") ||week. contains ("Sunday"))

    {

    System. out. println ("List has a weekend");

    return true;

    }

    else{

    System. out. println ("List has no weekend");

    return false;

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “You are developing a system to process lists of days of the week, represented as strings. Create a function is_weekend that consumes a list ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers