Writing Classes. Write a class to represent a Twitter account. An account has a
ID: 3832860 • Letter: W
Question
Writing Classes. Write a class to represent a Twitter account. An account has a String id, an email address and a list of all hashtags (use an ArrayList) used by this account. a. Write a class skeleton with appropriate variable declarations. b. Write a constructor that creates an account using the specified id and email address. The list of hashtags is initialized to be empty. c. Write a method named checkHashtag(String tag) that returns true if the given tag was ever used by the account, false otherwise. Use the contains (Object o) method from the ArrayList class to do the search.Explanation / Answer
Please find my answer.
import java.util.ArrayList;
public class Twitter {
private String id;
private String email;
private ArrayList<String> hashtags;
public Twitter(String id, String email) {
this.id = id;
this.email = email;
hashtags = new ArrayList<>();
}
public boolean checkHashtag(String tag){
return hashtags.contains(tag);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.