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
c380ebdd
Commit
c380ebdd
authored
Apr 17, 2021
by
MostafaRahmati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor Bug Fixed.
parent
1d3b43e7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
53 deletions
+73
-53
Main.java
src/Main.java
+38
-26
Voting.java
src/Voting.java
+33
-21
VotingSystem.java
src/VotingSystem.java
+2
-6
No files found.
src/Main.java
View file @
c380ebdd
...
...
@@ -6,57 +6,69 @@ public class Main {
*
*/
public
static
void
main
(
String
[]
args
)
{
VotingSystem
s
ystem
=
new
VotingSystem
();
ArrayList
<
String
>
singleVoting
=
new
ArrayList
<
String
>();
VotingSystem
votingS
ystem
=
new
VotingSystem
();
ArrayList
<
String
>
singleVoting
=
new
ArrayList
<>();
singleVoting
.
add
(
"option1"
);
singleVoting
.
add
(
"option2"
);
singleVoting
.
add
(
"option3"
);
Voting
voting1
=
s
ystem
.
createVoting
(
0
,
"Enter Selected Option Please..."
,
singleVoting
);
Voting
voting1
=
votingS
ystem
.
createVoting
(
0
,
"Enter Selected Option Please..."
,
singleVoting
);
Person
person1
=
new
Person
(
"firstName1"
,
"lastName1"
);
Person
person2
=
new
Person
(
"firstName"
,
"lastName2"
);
Person
person3
=
new
Person
(
"firstName3"
,
"lastName3"
);
Person
person4
=
new
Person
(
"firstName4"
,
"lastName4"
);
system
.
vote
(
voting1
,
person1
,
"option1"
);
system
.
vote
(
voting1
,
person2
,
"option2"
);
system
.
vote
(
voting1
,
person3
,
"option3"
);
system
.
vote
(
voting1
,
person4
,
"option2"
);
ArrayList
<
String
>
person1Votes
=
new
ArrayList
<>();
person1Votes
.
add
(
"option1"
);
ArrayList
<
String
>
person2Votes
=
new
ArrayList
<>();
person2Votes
.
add
(
"option2"
);
ArrayList
<
String
>
person3Votes
=
new
ArrayList
<>();
person3Votes
.
add
(
"option1"
);
ArrayList
<
String
>
person4Votes
=
new
ArrayList
<>();
person4Votes
.
add
(
"option3"
);
votingSystem
.
vote
(
voting1
,
person1
,
person1Votes
,
0
);
votingSystem
.
vote
(
voting1
,
person2
,
person2Votes
,
0
);
votingSystem
.
vote
(
voting1
,
person3
,
person3Votes
,
0
);
votingSystem
.
vote
(
voting1
,
person4
,
person4Votes
,
0
);
s
ystem
.
printVotingResult
(
voting1
,
0
);
votingS
ystem
.
printVotingResult
(
voting1
,
0
);
ArrayList
<
String
>
multipleVoting
=
new
ArrayList
<>();
multipleVoting
.
add
(
"option11"
);
multipleVoting
.
add
(
"option21"
);
multipleVoting
.
add
(
"option31"
);
Voting
voting2
=
s
ystem
.
createVoting
(
1
,
"Please Enter Your Choice For Multiple System"
Voting
voting2
=
votingS
ystem
.
createVoting
(
1
,
"Please Enter Your Choice For Multiple System"
,
multipleVoting
);
ArrayList
<
String
>
person1Votes
=
new
ArrayList
<>();
person1Votes
.
add
(
"option11"
);
person1Votes
.
add
(
"option21"
);
ArrayList
<
String
>
person1Votes
Multiple
=
new
ArrayList
<>();
person1Votes
Multiple
.
add
(
"option11"
);
person1Votes
Multiple
.
add
(
"option21"
);
ArrayList
<
String
>
person2Votes
=
new
ArrayList
<>();
person2Votes
.
add
(
"option11"
);
person2Votes
.
add
(
"option31"
);
ArrayList
<
String
>
person2Votes
Multiple
=
new
ArrayList
<>();
person2Votes
Multiple
.
add
(
"option11"
);
person2Votes
Multiple
.
add
(
"option31"
);
ArrayList
<
String
>
person3Votes
=
new
ArrayList
<>();
person3Votes
.
add
(
"option11"
);
person3Votes
.
add
(
"option21"
);
ArrayList
<
String
>
person3Votes
Multiple
=
new
ArrayList
<>();
person3Votes
Multiple
.
add
(
"option11"
);
person3Votes
Multiple
.
add
(
"option21"
);
ArrayList
<
String
>
person4Votes
=
new
ArrayList
<>();
person4Votes
.
add
(
"option11"
);
person4Votes
.
add
(
"option21"
);
ArrayList
<
String
>
person4Votes
Multiple
=
new
ArrayList
<>();
person4Votes
Multiple
.
add
(
"option11"
);
person4Votes
Multiple
.
add
(
"option21"
);
system
.
vote
(
voting2
,
person1
,
person1Votes
);
system
.
vote
(
voting2
,
person2
,
person2Votes
);
system
.
vote
(
voting2
,
person3
,
person3Votes
);
system
.
vote
(
voting2
,
person4
,
person4Votes
);
votingSystem
.
vote
(
voting2
,
person1
,
person1VotesMultiple
,
1
);
votingSystem
.
vote
(
voting2
,
person2
,
person2VotesMultiple
,
1
);
votingSystem
.
vote
(
voting2
,
person3
,
person3VotesMultiple
,
1
);
votingSystem
.
vote
(
voting2
,
person4
,
person4VotesMultiple
,
1
);
s
ystem
.
printVotingResult
(
voting2
,
1
);
votingS
ystem
.
printVotingResult
(
voting2
,
1
);
}
}
\ No newline at end of file
src/Voting.java
View file @
c380ebdd
...
...
@@ -39,7 +39,7 @@ public class Voting {
this
.
type
=
type
;
this
.
question
=
question
;
this
.
options
=
options
;
this
.
voters
=
new
ArrayList
<
Person
>();
this
.
voters
=
new
ArrayList
<>();
this
.
polls
=
new
HashMap
<
String
,
HashSet
<
Vote
>>();
}
...
...
@@ -55,10 +55,10 @@ public class Voting {
* @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
,
int
type
)
{
this
.
voters
.
add
(
person
);
if
(
type
==
1
){
for
(
String
selectedOption
:
selectedOptions
)
{
if
(!
this
.
polls
.
containsKey
(
selectedOption
))
{
HashSet
<
Vote
>
voteSet
=
new
HashSet
<>();
...
...
@@ -72,20 +72,32 @@ public class Voting {
}
}
/**
* @param person voter
* @param selectedOption selected option by voter in single type
*/
public
void
vote
(
Person
person
,
String
selectedOption
)
{
this
.
voters
.
add
(
person
);
else
{
String
selectedOption
=
selectedOptions
.
get
(
0
);
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
);
}
}
// /**
// * @param person voter
// * @param selectedOption selected option by voter in single type
// */
// 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);
// }
/**
* @return voters list
*/
...
...
src/VotingSystem.java
View file @
c380ebdd
...
...
@@ -58,15 +58,11 @@ public class VotingSystem {
* @param person the voter
* @param selectedOptions options which are selected
*/
public
void
vote
(
Voting
voting
,
Person
person
,
ArrayList
<
String
>
selectedOptions
)
{
voting
.
vote
(
person
,
selectedOptions
);
public
void
vote
(
Voting
voting
,
Person
person
,
ArrayList
<
String
>
selectedOptions
,
int
type
)
{
voting
.
vote
(
person
,
selectedOptions
,
type
);
}
public
void
vote
(
Voting
voting
,
Person
person
,
String
selectedOption
)
{
voting
.
vote
(
person
,
selectedOption
);
}
public
void
printVotingResult
(
Voting
voting
,
int
type
)
{
System
.
out
.
println
(
voting
.
getQuestion
());
...
...
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