You are given the class named ChatRoom that keeps a list of User objects. Your task is to write a class that will implement the UserIterator interface in the following way: the iterator must iterate only over non-blocked users, skipping the blocked ones. Also, implement the public UserIterator iterator() method in ChatRoom.
Iterator
List iterator
Report a typo
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;
interface UserIterator {
boolean hasNext();
boolean hasPrevious();
User next();
User previous();
}
class User {
private final String name;
private boolean blocked = false;
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setBlocked(boolean blocked) {
this.blocked = blocked;
}
public boolean isBlocked() {
return blocked;
}
}
class ChatRoom {
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.