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.

Respuesta :

ijeggs

Answer:

   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<String> 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;

       }

   }

}

ACCESS MORE
EDU ACCESS
Universidad de Mexico