Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
labSessionFour
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9931069
labSessionFour
Commits
87823f7e
Commit
87823f7e
authored
Apr 17, 2021
by
MostafaRahmati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Voting Completed.
parent
6468d613
Pipeline
#5935
canceled with stages
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
9 deletions
+68
-9
Voting.java
src/Voting.java
+68
-0
VotingSystem.java
src/VotingSystem.java
+0
-9
No files found.
src/Voting.java
View file @
87823f7e
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
;
}
}
src/VotingSystem.java
View file @
87823f7e
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment