Commit 1d3b43e7 authored by MostafaRahmati's avatar MostafaRahmati

JavaDoc Added.

parent 22bc950f
Pipeline #5939 failed with stages
import java.util.ArrayList; import java.util.ArrayList;
public class Main { public class Main {
/**
* @param args System Args
*
*/
public static void main(String[] args) { public static void main(String[] args) {
VotingSystem system = new VotingSystem(); VotingSystem system = new VotingSystem();
ArrayList<String> singleVoting = new ArrayList<String>(); ArrayList<String> singleVoting = new ArrayList<String>();
......
...@@ -2,19 +2,32 @@ public class Person { ...@@ -2,19 +2,32 @@ public class Person {
private String firstName; private String firstName;
private String lastName; private String lastName;
/**
* @param firstName of voter
* @param lastName of voter
*/
public Person(String firstName, String lastName) { public Person(String firstName, String lastName) {
this.firstName = firstName; this.firstName = firstName;
this.lastName = lastName; this.lastName = lastName;
} }
/**
* @return first name
*/
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
/**
* @return last name of voter
*/
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
/**
* @return name of voter attached to his/her last name
*/
@Override @Override
public String toString() { public String toString() {
return firstName + " " + lastName; return firstName + " " + lastName;
......
...@@ -2,23 +2,40 @@ import ir.huri.jcal.JalaliCalendar; ...@@ -2,23 +2,40 @@ import ir.huri.jcal.JalaliCalendar;
import java.util.Objects; import java.util.Objects;
/**
* class for vote
*/
public class Vote { public class Vote {
private Person person; private Person person;
private JalaliCalendar date; private JalaliCalendar date;
/**
* @param person who voted
* @param date jalali date of vote
*/
public Vote(Person person, JalaliCalendar date) { public Vote(Person person, JalaliCalendar date) {
this.date = date; this.date = date;
this.person = person; this.person = person;
} }
/**
* @return voter
*/
public Person getPerson() { public Person getPerson() {
return person; return person;
} }
/**
* @return jalali date as a string
*/
public JalaliCalendar getDate() { public JalaliCalendar getDate() {
return date; return date;
} }
/**
* @param o the object being compared
* @return boolean value of equality
*/
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
...@@ -27,6 +44,9 @@ public class Vote { ...@@ -27,6 +44,9 @@ public class Vote {
return getPerson().equals(vote.getPerson()) && getDate().equals(vote.getDate()); return getPerson().equals(vote.getPerson()) && getDate().equals(vote.getDate());
} }
/**
* @return hashcode person and date
*/
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(getPerson(), getDate()); return Objects.hash(getPerson(), getDate());
......
...@@ -4,6 +4,9 @@ import java.util.ArrayList; ...@@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
/**
* Voting Class
*/
public class Voting { public class Voting {
private int type; private int type;
private String question; private String question;
...@@ -11,15 +14,27 @@ public class Voting { ...@@ -11,15 +14,27 @@ public class Voting {
private HashSet<String> options; private HashSet<String> options;
private HashMap<String, HashSet<Vote>> polls; private HashMap<String, HashSet<Vote>> polls;
/**
* @return returns the question text
*/
public String getQuestion() { public String getQuestion() {
return question; return question;
} }
/**
* @param type type of voting. 0 is single and 1 is multiple
* @param question question text of voting
*/
public Voting(int type, String question) { public Voting(int type, String question) {
this(type, question, new HashSet<>()); this(type, question, new HashSet<>());
} }
/**
* @param type type of voting. 0 is single and 1 is multiple
* @param question question text of voting
* @param options options for voting
*/
public Voting(int type, String question, HashSet<String> options) { public Voting(int type, String question, HashSet<String> options) {
this.type = type; this.type = type;
this.question = question; this.question = question;
...@@ -29,10 +44,17 @@ public class Voting { ...@@ -29,10 +44,17 @@ public class Voting {
} }
/**
* @param string have no idea what it is
*/
public void createPoll(String string) { public void createPoll(String string) {
// Not Clarified What It Does In The Documentation // Not Clarified What It Does In The Documentation
} }
/**
* @param person voter
* @param selectedOptions selected options by voter in multiple type
*/
public void vote(Person person, ArrayList<String> selectedOptions) { public void vote(Person person, ArrayList<String> selectedOptions) {
this.voters.add(person); this.voters.add(person);
...@@ -51,6 +73,10 @@ public class Voting { ...@@ -51,6 +73,10 @@ public class Voting {
} }
/**
* @param person voter
* @param selectedOption selected option by voter in single type
*/
public void vote(Person person, String selectedOption) { public void vote(Person person, String selectedOption) {
this.voters.add(person); this.voters.add(person);
HashSet<Vote> voteSet = this.polls.containsKey(selectedOption) ? HashSet<Vote> voteSet = this.polls.containsKey(selectedOption) ?
...@@ -60,10 +86,16 @@ public class Voting { ...@@ -60,10 +86,16 @@ public class Voting {
this.polls.put(selectedOption, voteSet); this.polls.put(selectedOption, voteSet);
} }
/**
* @return voters list
*/
public ArrayList<Person> getVoters() { public ArrayList<Person> getVoters() {
return voters; return voters;
} }
/**
* @param type type of voting. 0 is single and 1 is multiple
*/
public void printVotes(int type) { public void printVotes(int type) {
for (String option : this.options) { for (String option : this.options) {
if (!this.polls.containsKey(option)) { if (!this.polls.containsKey(option)) {
...@@ -82,10 +114,16 @@ public class Voting { ...@@ -82,10 +114,16 @@ public class Voting {
} }
} }
/**
* @return all polls
*/
public HashMap<String, HashSet<Vote>> getPolls() { public HashMap<String, HashSet<Vote>> getPolls() {
return polls; return polls;
} }
/**
* @return type of voting
*/
public int getType() { public int getType() {
return type; return type;
} }
......
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
/**
* Voting System
*/
public class VotingSystem { public class VotingSystem {
private ArrayList<Voting> votingList; private ArrayList<Voting> votingList;
/**
* Constructor
*/
public VotingSystem() { public VotingSystem() {
this.votingList = new ArrayList<>(); this.votingList = new ArrayList<>();
} }
/**
* @param type of voting. 0 is single and 1 is multiple
* @param question for voting
* @param optionsList for voting
* @return a vote
*/
public Voting createVoting(int type, String question, ArrayList<String> optionsList) { public Voting createVoting(int type, String question, ArrayList<String> optionsList) {
HashSet<String> optionsSet = new HashSet<>(optionsList); HashSet<String> optionsSet = new HashSet<>(optionsList);
Voting voting = new Voting(type, question, optionsSet); Voting voting = new Voting(type, question, optionsSet);
...@@ -17,11 +29,18 @@ public class VotingSystem { ...@@ -17,11 +29,18 @@ public class VotingSystem {
} }
/**
* @return a list of votings
*/
public ArrayList<Voting> getVotingList() { public ArrayList<Voting> getVotingList() {
return votingList; return votingList;
} }
/**
* @param type type of voting
* @return a list of voting by type
*/
public ArrayList<Voting> getVoting(int type) { public ArrayList<Voting> getVoting(int type) {
ArrayList<Voting> sameVoting = new ArrayList<>(); ArrayList<Voting> sameVoting = new ArrayList<>();
...@@ -34,6 +53,11 @@ public class VotingSystem { ...@@ -34,6 +53,11 @@ public class VotingSystem {
} }
/**
* @param voting vote to a specific option
* @param person the voter
* @param selectedOptions options which are selected
*/
public void vote(Voting voting, Person person, ArrayList<String> selectedOptions) { public void vote(Voting voting, Person person, ArrayList<String> selectedOptions) {
voting.vote(person, selectedOptions); voting.vote(person, selectedOptions);
} }
......
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