Here is a blueJ method will three class,The ChatBot class is a concrete subclass; it should inherit both Robot and Chatty.
It has a single constructor that takes two parameters: a name and a number. It instantiates
both friends and chatRecords fields with an empty list.
The name of the chatbot should be set to the given name.
The level of the chatbot should be set to the given number if it is within the range
[LEVEL_MIN, LEVEL_MAX]. If the given number is less than LEVEL_MIN, the level is set
to LEVEL_MIN; if the number is greater than LEVEL_MAX, the level is set to LEVEL_MAX.
In the ChatBot class i get an error on this line public class ChatBot extends Robot implements Chatty which says ChatBot is not abstract and does not override abstract method hasAI() in Robot. How do i fix this error
What I have tried:
<pre>import java.util.ArrayList;
import java.util.List;
public class ChatBot extends Robot implements Chatty{
private int level;
private final List<ChatBot> friends;
private final List<String> chatRecords;
public ChatBot(String name, int level) {
super(name);
this.level = Math.min(Math.max(level, LEVEL_MIN), LEVEL_MAX);
this.friends = new ArrayList<>();
this.chatRecords = new ArrayList<>();
if (level < LEVEL_MIN) {
this.level = LEVEL_MIN;
} else if (level > LEVEL_MAX) {
this.level = LEVEL_MAX;
} else {
this.level = level;
}
}
public void addFriend(ChatBot bot) {
friends.add(bot);
}
public int getLevel() {
return level;
}
public List<ChatBot> getFriends() {
return friends;
}
public List<String> getChatRecords() {
return chatRecords;
}
public void addChatRecord(char type, String chat) {
if (type == 'Q' || type == 'A') {
chatRecords.add(type + ":" + chat);
}
else {
System.out.println("Wrong type.");
}
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ChatBot bot)) {
return false;
}
return super.equals(bot) && level == bot.getLevel();
}
}
public abstract class Robot {
private final String name;
public Robot(String name) {
this.name = name;
}
public String getName() {
return name;
}
public abstract boolean hasAI();
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Robot)) {
return false;
}
var bot = (Robot) obj;
return name.equals(bot.getName());
}
}
import java.util.HashMap;
import java.util.Map;
public interface Chatty {
int LEVEL_MIN = 1;
int LEVEL_MAX = 3;
Map<String,String> QA = new HashMap<>(Map.of(
"Hello, how are you?", "I'm great, thanks.",
"What are you?", "I am a chatbot",
"Do you have a hobby?", "I like chatting with you.",
"Can you tell a joke?", "You are very funny!",
"What is the capital of UK?", "London",
"Do you like Java?", "Yes of course.",
"Are you a robot?", "Yes I'm a robot, but I'm a smart one!",
"Do you get smarter?", "I hope so."
));
String question();
String answer(String question);
}