Ask Question
27 March, 00:51

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.

+3
Answers (1)
  1. 27 March, 03:36
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers