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
db5a7b37
Commit
db5a7b37
authored
Apr 17, 2021
by
MostafaRahmati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VotingSystem Completed.
Another Constructor Added to Voting
parent
87823f7e
Pipeline
#5936
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
10 deletions
+59
-10
Voting.java
src/Voting.java
+19
-7
VotingSystem.java
src/VotingSystem.java
+40
-3
No files found.
src/Voting.java
View file @
db5a7b37
...
@@ -15,13 +15,22 @@ public class Voting {
...
@@ -15,13 +15,22 @@ public class Voting {
return
question
;
return
question
;
}
}
public
Voting
(
int
type
,
String
question
){
public
Voting
(
int
type
,
String
question
)
{
this
.
type
=
type
;
this
(
type
,
question
,
new
HashSet
<>());
this
.
question
=
question
;
}
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
){
// Not Clarified What It Does In The Documentation
public
void
createPoll
(
String
string
)
{
// Not Clarified What It Does In The Documentation
}
}
public
void
vote
(
Person
person
,
ArrayList
<
String
>
selectedOptions
)
{
public
void
vote
(
Person
person
,
ArrayList
<
String
>
selectedOptions
)
{
...
@@ -42,7 +51,6 @@ public class Voting {
...
@@ -42,7 +51,6 @@ public class Voting {
}
}
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
)
?
...
@@ -56,7 +64,7 @@ public class Voting {
...
@@ -56,7 +64,7 @@ public class Voting {
return
voters
;
return
voters
;
}
}
public
void
printVotes
(){
public
void
printVotes
()
{
for
(
String
option
:
this
.
options
)
{
for
(
String
option
:
this
.
options
)
{
if
(!
this
.
polls
.
containsKey
(
option
))
{
if
(!
this
.
polls
.
containsKey
(
option
))
{
System
.
out
.
println
(
option
+
" : 0"
);
System
.
out
.
println
(
option
+
" : 0"
);
...
@@ -70,4 +78,8 @@ public class Voting {
...
@@ -70,4 +78,8 @@ public class Voting {
public
HashMap
<
String
,
HashSet
<
Vote
>>
getPolls
()
{
public
HashMap
<
String
,
HashSet
<
Vote
>>
getPolls
()
{
return
polls
;
return
polls
;
}
}
public
int
getType
()
{
return
type
;
}
}
}
src/VotingSystem.java
View file @
db5a7b37
...
@@ -2,13 +2,50 @@ import java.util.ArrayList;
...
@@ -2,13 +2,50 @@ import java.util.ArrayList;
import
java.util.HashSet
;
import
java.util.HashSet
;
public
class
VotingSystem
{
public
class
VotingSystem
{
private
int
type
;
private
String
question
;
private
ArrayList
<
Voting
>
votingList
;
private
ArrayList
<
Voting
>
votingList
;
public
VotingSystem
()
{
public
VotingSystem
()
{
this
.
votingList
=
new
ArrayList
<>();
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
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