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 <em>java.util.ArrayList</em> and <em>import java.util.List;</em> 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
<em>import java.util.ArrayList;</em>
<em>import java.util.List;</em>
<em>public class Car {</em>
<em> public static void main(String[] args) {</em>
<em> List<String> daysOfWeek = new ArrayList<>();</em>
<em> daysOfWeek.add("Sunday");</em>
<em> daysOfWeek.add("Moday");</em>
<em> daysOfWeek.add("Tuesday");</em>
<em> daysOfWeek.add("Wednesday");</em>
<em> daysOfWeek.add("Thursday");</em>
<em> daysOfWeek.add("Friday");</em>
<em> daysOfWeek.add("Saturday");</em>
<em> is_weekend(daysOfWeek);</em>
<em> }</em>
<em> public static boolean is_weekend(List week){</em>
<em> if(week.contains("Saturday")||week.contains("Sunday"))</em>
<em> {</em>
<em> System.out.println("List has a weekend");</em>
<em> return true;</em>
<em> }</em>
<em> else{</em>
<em> System.out.println("List has no weekend");</em>
<em> return false;</em>
<em> }</em>
<em> }</em>
}