Voting System
Presentation Slides
User story and CRC cards:
User story: URL: https://docs.google.com/a/cs.unc.edu/document/d/1lKKvOphoqgzlOC53M6f-wxaBjBnKZnBcMnVtz9LLMas/edit
CRC Cards: URL: https://docs.google.com/a/cs.unc.edu/spreadsheet/ccc?key=0Au-0QXysWcRXdHBtc3lDeVlURVNLMHg4WWlvWHFKeVE#gid=0
finaldesign.pptx | |
File Size: | 962 kb |
File Type: | pptx |
Source Code to demonstrate the system design
voting_5.java | |
File Size: | 4 kb |
File Type: | java |
Overview of the Design
Here we have the overall design diagram as well as the sub-systems design.
Registration: Proxy pattern and Singleton
Return the result
Authentication: Proxy design pattern
Regional Level Ballot: Composite & Chain of responsibility
Voter Factory
Voting
Updating candidate information: Observer
Pattern discussion
pattern_discussion.pdf | |
File Size: | 239 kb |
File Type: |
Assignment 11
source_code.zip | |
File Size: | 4 kb |
File Type: | zip |
Assignment 10
In our design, we seperate the subject from the GUI, and store a set of proxies in the subject. Each proxy will link to one observer, and handle network communications. Ons the proxy is created, and registered as an observer using the 2-way registration, it will listen on pre-determined port for the observer process(Observer1, Observer2, Observer3).
UML:
UML:
Source code is as below:
code.zip | |
File Size: | 9 kb |
File Type: | zip |
Assignment 9
Our CRC Card sample format is as follows:
So our CRC cards is as follows:
Assignment 8
Zhi Dong, Xiao Yang
Basic functions:
If press an even number, as the assignment required, it’ll return a number multiply 3. If it mods 6 is zero, it’ll return -1.
If we input an odd number, it’ll return a random number, if we input again within 30 seconds, it won’t change since a cached result is returned, and if the elapse time is beyond 30 seconds, it will request server over network, so a new random number will be returned.
If the input number is a prime number, it simply returns a value plus by 1 from server through the network.
How to run it.
The server process: PrimeProcess.java and OddProcess.java should be run before the clients start( we use host pc address “127.0.0.1” with port “9000” ).
Run Flyweight_assignment.java as our client program.
Architecture:
Handler is the interface for OddHandler, PrimeHandler, EvenHandler.
Basic functions:
If press an even number, as the assignment required, it’ll return a number multiply 3. If it mods 6 is zero, it’ll return -1.
If we input an odd number, it’ll return a random number, if we input again within 30 seconds, it won’t change since a cached result is returned, and if the elapse time is beyond 30 seconds, it will request server over network, so a new random number will be returned.
If the input number is a prime number, it simply returns a value plus by 1 from server through the network.
How to run it.
The server process: PrimeProcess.java and OddProcess.java should be run before the clients start( we use host pc address “127.0.0.1” with port “9000” ).
Run Flyweight_assignment.java as our client program.
Architecture:
Handler is the interface for OddHandler, PrimeHandler, EvenHandler.
The core function in Handler is: int calculate(int num); which simply calculates the number and return the output.
The Proxy class is the client Proxy which sends the request to the server.
The SimpleServerProxy class is for even handler.
The process only uses net proxy as a main function to receive data, process it and return the result.
The source code for this assignment is as follows:
The Proxy class is the client Proxy which sends the request to the server.
The SimpleServerProxy class is for even handler.
The process only uses net proxy as a main function to receive data, process it and return the result.
The source code for this assignment is as follows:
assignmentcode.zip | |
File Size: | 11 kb |
File Type: | zip |
Assignment 7
User story:
As a <role>, I want <goal/desire> so that <benefit>
As <who> <when> <where>, I <what> because <why>.
As an official, I want to log into the system.
As an official, I want to restrict the voters to those who have citizenship, are old enough and have registered so that only those who satisfied these could vote.
As the official, I want to have authentication so that one voter could only have one vote.
As the official, I want the voters to supply personal informations such as SSN, or to supply biometric information and create a database to store them, in order to realize authentication.
As the official, I want the voting process to be confidential.
As an official, I want to view the profile of candidates.
As the official, I want to be able to view intermediate and final results.
As a researcher, I want to be able to log into the system.
As a researcher, I want to be able to access the historical data.
As a researcher, I want to be able to view result during an election.
As a researcher, I want to view details of an election.
As a candidate, I want to log into the system.
As the candidate, I want to edit my profile so that voters could see my information.
As a voter, I want to be able to vote from different platforms such as smartphones, tablet computers, laptop and desktop computers, etc.
As a voter, I want to vote in different ways such as via text message, on web interface and from certain applications.
As a voter, I want to log into the voting system so I could vote.
As a voter, I want to vote.
As a voter, I want to view the final result of the election.
As a voter, I want to be able to change my vote before deadline.
As a voter, I want to view the profiles of the candidates.
As a <role>, I want <goal/desire> so that <benefit>
As <who> <when> <where>, I <what> because <why>.
As an official, I want to log into the system.
As an official, I want to restrict the voters to those who have citizenship, are old enough and have registered so that only those who satisfied these could vote.
As the official, I want to have authentication so that one voter could only have one vote.
As the official, I want the voters to supply personal informations such as SSN, or to supply biometric information and create a database to store them, in order to realize authentication.
As the official, I want the voting process to be confidential.
As an official, I want to view the profile of candidates.
As the official, I want to be able to view intermediate and final results.
As a researcher, I want to be able to log into the system.
As a researcher, I want to be able to access the historical data.
As a researcher, I want to be able to view result during an election.
As a researcher, I want to view details of an election.
As a candidate, I want to log into the system.
As the candidate, I want to edit my profile so that voters could see my information.
As a voter, I want to be able to vote from different platforms such as smartphones, tablet computers, laptop and desktop computers, etc.
As a voter, I want to vote in different ways such as via text message, on web interface and from certain applications.
As a voter, I want to log into the voting system so I could vote.
As a voter, I want to vote.
As a voter, I want to view the final result of the election.
As a voter, I want to be able to change my vote before deadline.
As a voter, I want to view the profiles of the candidates.
Assignment 6
Click the Below Button to view the Source Code
Class Diagram
In this assignment, we implemented 5 classes: Place, Nation, State, Local. The Place is base class for Nation, State, Local. It is obvious that Nation, State are the inner nodes, and local is the leaf. In composite pattern, for the common operations, the leaf level and the inner levels look the same. So the base class has three virtual functions to be overriden by subclasses.
virtual string returnLevel()=0; // return its political level which is nation, state or local
virtual vector<int> returnVoteSum()=0;// return its sum of votes for each candidate.
virtual void addSubplace(Place* p) = 0;// for instance, a state can add a local, or a nation add a state. ...
The code of base class: Place class is as follows:
class Place
{
protected:
string name;
int canditateNumber;
vector<string> candidateName;
public:
Place(string name)
{
canditateNumber = 2;
this->name = name;
this->candidateName.push_back("Obama");
this->candidateName.push_back("Romney");
}
string returnName(){return name;}
vector<string> returnCandidateName(){return candidateName;}
virtual string returnLevel()=0;
virtual vector<int> returnVoteSum()=0;
virtual void addSubplace(Place* p) = 0;
};
The Nation class contains a set of sub places which are states belong to this state, since we know that the composition pattern also inlcudes a container. It also overrides the functions in base class.
class Nation:public Place{
public:
Nation(string name):Place(name){}
string returnLevel(){return "Nation";}
vector<int> returnVoteSum();
void addSubplace(Place* p){subPlaces.push_back(p);}
private:
vector<Place*> subPlaces;
};
Similarly, the state class is as follows:
class State:public Place{
public:
State(string name):Place(name){}
string returnLevel(){return "State";}
vector<int> returnVoteSum();
void addSubplace(Place* p){subPlaces.push_back(p);}
private:
vector<Place*> subPlaces;
};
The local class is tricky, here we don't use a subPlaces since local is leaf node, we have a set of vote data for each candidates which is used to sum up the total votes of a state or the nation.
class Local:public Place{
public:
Local(string name, vector<int> VoteSum);
string returnLevel(){return "Local";}
vector<int> returnVoteSum(){return VoteSum;}
void addSubplace(Place* p){}
private:
vector<int> VoteSum;
};
Here is the factory class: CreatePlace. This class is used to create different kinds of places like locals, states, or nation.
class createPlace{
public:
static Place* createNation(string name)
{
return new Nation(name);
}
static Place* createState(string name)
{
return new State(name);
}
static Place* createLocal(string name, vector<int> VoteSum)
{
return new Local(name, VoteSum);
}
};
The operations you put into the common interface.
We need a returnVoteSum() function to calculate the sum of votes within this region, in nation class and state class, it is like this:
vector<int> State::returnVoteSum()
{
vector<int> result(canditateNumber, 0);
for(int i = 0; i < this->subPlaces.size(); i++)
{
vector<int> lowerResult = this->subPlaces[i]->returnVoteSum();
for(int idx = 0; idx < canditateNumber; idx++)
{
result[idx] += lowerResult[idx];
}
}
return result;
}
And the Local class only return the vector which is genreated by inpurt information.
vector<int> returnVoteSum(){return VoteSum;}
we need a returnVoteSum() function to return the political level of current place. In this case, different political levels will return different values, just as follows:
Local Class
string returnLevel(){return "Local";}
State Class
string returnLevel(){return "State";}
Nation Class
string returnLevel(){return "Nation";}
how to run the program... what input to provide, and a description of what sort of output is generated.
We simulate the voting in different counties using the random method. We let the user input the population votes for this election and then output the result of votes for Obama and Romney.
COMP 723 Homework and Demo
Zhi Dong email: zhidong at cs dot unc dot edu
Assignment2
Problem Description
Use ML to express the axioms you write. Using ML will also allow you to check the behavior to see if you have expressed what you intended.
Using Guttag's hueristic, give consistent and complete algebraic specs for this ADT (class):
LIB (library) new: -> LIB add: LIB x BOOK -> LIB rem: LIB x BOOK -> LIB cko: LIB x BOOK x PERSON -> LIB cki: LIB x BOOK x PERSON -> LIB wait: LIB x BOOK x PERSON -> LIB off: LIB x BOOK x PERSON -> LIB has: LIB x BOOK -> boolean here: LIB x BOOK -> int num: LIB x BOOK -> int new makes a LIB with no books, no wait lists, etc. add puts another copy of a book in the library rem takes a copy out of the library cko allows a person to check out the book cki checks the book back in; if there is a person on wait list it does a cko to that person. wait puts person at the back of a waiting list for a book off takes a person out of the waiting list for a book has tells if a book exists in the Library (even if all copies are checked out here tells how many copies of a book are available for checking out num tells how many copies total of a book exist in the library
Basic Idea
My understanding, I implemented 2 datatypes, the first datatype is Lib and the other is waiting list datatype. Lib have two constructors, one is con means add a book that has not been assigned, and conPeople means that this book has been checked out. And it is easy to count the total number ,just count both conPeople and con, and count the here is just count the con. I have implemented the sample test case to test the num, here, has, function. The cki and cko performs the replacement of con and conPeople.
The waiting list is easy, just implement a queue to determine the man has the right to check out and check in the book.
Problem Description
Use ML to express the axioms you write. Using ML will also allow you to check the behavior to see if you have expressed what you intended.
Using Guttag's hueristic, give consistent and complete algebraic specs for this ADT (class):
LIB (library) new: -> LIB add: LIB x BOOK -> LIB rem: LIB x BOOK -> LIB cko: LIB x BOOK x PERSON -> LIB cki: LIB x BOOK x PERSON -> LIB wait: LIB x BOOK x PERSON -> LIB off: LIB x BOOK x PERSON -> LIB has: LIB x BOOK -> boolean here: LIB x BOOK -> int num: LIB x BOOK -> int new makes a LIB with no books, no wait lists, etc. add puts another copy of a book in the library rem takes a copy out of the library cko allows a person to check out the book cki checks the book back in; if there is a person on wait list it does a cko to that person. wait puts person at the back of a waiting list for a book off takes a person out of the waiting list for a book has tells if a book exists in the Library (even if all copies are checked out here tells how many copies of a book are available for checking out num tells how many copies total of a book exist in the library
Basic Idea
My understanding, I implemented 2 datatypes, the first datatype is Lib and the other is waiting list datatype. Lib have two constructors, one is con means add a book that has not been assigned, and conPeople means that this book has been checked out. And it is easy to count the total number ,just count both conPeople and con, and count the here is just count the con. I have implemented the sample test case to test the num, here, has, function. The cki and cko performs the replacement of con and conPeople.
The waiting list is easy, just implement a queue to determine the man has the right to check out and check in the book.
- This is a form of bounded queue; if the ring is full, and you add an item, then it over-writes the oldest item (the one at the front). You can think of the finite number of elements as being in a circle (the ring), and you keep adding around the ring. Operations will be new, add, rem, next (or front), size, max, empty, full.
- stomp stack
- This is a form of bounded stack; when you push an item on a full stack, it "mashes" the bottom item out of the stack to make room at the top. Operations are new, push, pop,
- top, size, max, empty, full. Remember you can create internal operations if they help you define the "public" operations.
- priority stack
- This will be an unbounded stack, and the stack contains elements that are "pairs": a value of some type, and an integer priority (with 0 as low priority). When you push an element, it percolates down toward the stack bottom until it hits an element with priority equal to or lower... and it stays there on top of that element. So within priority categories, it maintains stack order of the element values. Operations are new, push, pop, size, empty, topv, topp. We implement the "pair" concept by asking separately what value is on top (topv) and what priority the top element has (topp). This is just a suggestion; you may do it differently if you wish, such as creating a pair type with its own operations.