Commit db5a7b37 authored by MostafaRahmati's avatar MostafaRahmati

VotingSystem Completed.

Another Constructor Added to Voting
parent 87823f7e
Pipeline #5936 canceled with stages
......@@ -15,12 +15,21 @@ public class Voting {
return question;
}
public Voting(int type, String question){
this.type=type;
this.question=question;
public Voting(int type, String question) {
this(type, question, new HashSet<>());
}
public Voting(int type, String question, HashSet<String> options) {
this.type = type;
this.question = question;
this.options = options;
this.voters = new ArrayList<Person>();
this.polls = new HashMap<String, HashSet<Vote>>();
}
public void createPoll(String string){
public void createPoll(String string) {
// Not Clarified What It Does In The Documentation
}
......@@ -42,7 +51,6 @@ public class Voting {
}
public void vote(Person person, String selectedOption) {
this.voters.add(person);
HashSet<Vote> voteSet = this.polls.containsKey(selectedOption) ?
......@@ -56,7 +64,7 @@ public class Voting {
return voters;
}
public void printVotes(){
public void printVotes() {
for (String option : this.options) {
if (!this.polls.containsKey(option)) {
System.out.println(option + " : 0");
......@@ -70,4 +78,8 @@ public class Voting {
public HashMap<String, HashSet<Vote>> getPolls() {
return polls;
}
public int getType() {
return type;
}
}
......@@ -2,13 +2,50 @@ import java.util.ArrayList;
import java.util.HashSet;
public class VotingSystem {
private int type;
private String question;
private ArrayList<Voting> votingList;
public VotingSystem() {
this.votingList = new ArrayList<>();
}
public Voting createVoting(int type, String question, ArrayList<String> optionsList) {
HashSet<String> optionsSet = new HashSet<>(optionsList);
Voting voting = new Voting(type, question, optionsSet);
this.votingList.add(voting);
return voting;
}
public ArrayList<Voting> getVotingList() {
return votingList;
}
public ArrayList<Voting> getVoting(int type) {
ArrayList<Voting> sameVoting = new ArrayList<>();
for (Voting voting : this.votingList) {
if (voting.getType() == type) {
sameVoting.add(voting);
}
}
return sameVoting;
}
public void vote(Voting voting, Person person, ArrayList<String> selectedOptions) {
voting.vote(person, selectedOptions);
}
public void vote(Voting voting, Person person, String selectedOption) {
voting.vote(person, selectedOption);
}
public void printVotingResult(Voting voting) {
System.out.println(voting.getQuestion());
voting.printVotes();
}
}
\ No newline at end of file
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