userfunctions
unknown
java
3 years ago
1.6 kB
3
Indexable
public String textInput() {
String cont;
Scanner sc = new Scanner(System.in);
StringBuilder sbf = new StringBuilder();
do {
String text = sc.nextLine();
sbf.append(text);
sbf.append("/");
System.out.println("Type YES to continue adding next line to the post, or type NO to finish");
cont = sc.nextLine();
}while(cont.equalsIgnoreCase("YES") || cont.startsWith("y"));
String tempText = sbf.toString();
return tempText;
}
public Post writePost() {
Post post = new Post();
post.setAuthor(this);
post.setText(textInput());
return post;
}
public void followUser(User user) {
if(user != this) {
followingList.add(user);
user.followerList.add(this);
System.out.println("Followed Successfully!" + user.getUsername());
}
else {
System.out.println("Error, You cannot follow yourself...");
}
}
public void likesPost(Post post) {
post.setLike(this);
System.out.println(this.username + "has liked the post by: " + post.getAuthor().getUsername() + "!");
}
public void commentOnPost(Post post, Comment comment) {
comment.setUser(this);
this.commentList.add(comment);
comment.setPost(post);
comment.setText(textInput());
post.setComment(comment);
}
Editor is loading...