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;
}
}
Step-by-step 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;
}
}
}