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
1d3b43e7
Commit
1d3b43e7
authored
Apr 17, 2021
by
MostafaRahmati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JavaDoc Added.
parent
22bc950f
Pipeline
#5939
failed with stages
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
0 deletions
+99
-0
Main.java
src/Main.java
+4
-0
Person.java
src/Person.java
+13
-0
Vote.java
src/Vote.java
+20
-0
Voting.java
src/Voting.java
+38
-0
VotingSystem.java
src/VotingSystem.java
+24
-0
No files found.
src/Main.java
View file @
1d3b43e7
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
>();
...
...
src/Person.java
View file @
1d3b43e7
...
@@ -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
;
...
...
src/Vote.java
View file @
1d3b43e7
...
@@ -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
());
...
...
src/Voting.java
View file @
1d3b43e7
...
@@ -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
;
}
}
...
...
src/VotingSystem.java
View file @
1d3b43e7
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
);
}
}
...
...
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