import java.util.HashMap;
import java.util.Map;
publicclass VoteCounter {
privateMap<String, Boolean> votes;
public VoteCounter() {
this.votes = new HashMap<>();
}
publicvoid vote(String candidate) {
if (votes.containsKey(candidate)) {
System.out.println("Sorry, " + candidate + " has already received your vote.");
} else {
votes.put(candidate, true);
System.out.println("Vote for " + candidate + " recorded successfully.");
}
}
publicstaticvoid main(String[] args) {
VoteCounter voteCounter = new VoteCounter();
voteCounter.vote("Candidate A"); // 输出: Vote for Candidate A recorded successfully.
voteCounter.vote("Candidate B"); // 输出: Vote for Candidate B recorded successfully.
voteCounter.vote("Candidate A"); // 输出: Sorry, Candidate A has already received your vote.
}
}