Ask Question
14 April, 20:46

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. 14 April, 21:11
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers