Commit 87823f7e authored by MostafaRahmati's avatar MostafaRahmati

Voting Completed.

parent 6468d613
Pipeline #5935 canceled with stages
import ir.huri.jcal.JalaliCalendar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class Voting {
private int type;
private String question;
private ArrayList<Person> voters;
private HashSet<String> options;
private HashMap<String, HashSet<Vote>> polls;
public String getQuestion() {
return question;
}
public Voting(int type, String question){
this.type=type;
this.question=question;
}
public void createPoll(String string){
// Not Clarified What It Does In The Documentation
}
public void vote(Person person, ArrayList<String> selectedOptions) {
this.voters.add(person);
for (String selectedOption : selectedOptions) {
if (!this.polls.containsKey(selectedOption)) {
HashSet<Vote> voteSet = new HashSet<>();
Vote vote = new Vote(person, new JalaliCalendar());
voteSet.add(vote);
this.polls.put(selectedOption, voteSet);
}
HashSet<Vote> voteSet = this.polls.get(selectedOption);
voteSet.add(new Vote(person, new JalaliCalendar()));
this.polls.put(selectedOption, voteSet);
}
}
public void vote(Person person, String selectedOption) {
this.voters.add(person);
HashSet<Vote> voteSet = this.polls.containsKey(selectedOption) ?
this.polls.get(selectedOption) : new HashSet<>();
Vote vote = new Vote(person, new JalaliCalendar());
voteSet.add(vote);
this.polls.put(selectedOption, voteSet);
}
public ArrayList<Person> getVoters() {
return voters;
}
public void printVotes(){
for (String option : this.options) {
if (!this.polls.containsKey(option)) {
System.out.println(option + " : 0");
}
HashSet<Vote> votes = this.polls.get(option);
System.out.println(option + " : " + votes.size());
}
}
public HashMap<String, HashSet<Vote>> getPolls() {
return polls;
}
}
......@@ -10,14 +10,5 @@ public class VotingSystem {
this.votingList = new ArrayList<>();
}
public Voting createVoting(int type, String question, ArrayList<String> optionsList) {
HashSet<String> optionsSet = new HashSet<String>(optionsList);
Voting voting = new Voting(type, question, optionsSet);
this.votingList.add(voting);
return voting;
this.type = type;
this.question = question;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment