From 0a09dff04be4677c3c80b19c74aaa8818b74334a Mon Sep 17 00:00:00 2001 From: MeetSakhareliya <74584967+MeetSakhareliya@users.noreply.github.com> Date: Mon, 9 Jun 2025 18:53:58 +0530 Subject: [PATCH] Author should not allowed to vote question --- solutions/java/src/stackoverflow/Question.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/java/src/stackoverflow/Question.java b/solutions/java/src/stackoverflow/Question.java index 039ff7cb..9c768458 100644 --- a/solutions/java/src/stackoverflow/Question.java +++ b/solutions/java/src/stackoverflow/Question.java @@ -44,6 +44,7 @@ public synchronized void acceptAnswer(Answer answer) { @Override public void vote(User voter, VoteType type) { + if(voter.equals(author)) return; //throw error -> Author shouldn't be allowed to vote votes.removeIf(v -> v.getVoter().equals(voter)); votes.add(new Vote(voter, type)); author.updateReputation(5 * (type == VoteType.UPVOTE ? 1 : -1)); // +5 for upvote, -5 for downvote @@ -81,4 +82,4 @@ private int generateId() { public Answer getAcceptedAnswer() { return acceptedAnswer; } -} \ No newline at end of file +}