CS 212 - Project Phase 1

Summer 2003

Due: Monday July 7th, 11:59pm


0. Objectives

 You will be designing and implementing an electronic voting system this semester. This system will follow a client-server architecture, in which various client programs connect over the internet to a server.  To begin, you will create the Graphical User Interfaces (GUIs) for the client and server programs.  While learning about GUIs and how to create them in Java, you will also be introduced to streams, and will learn how to properly design your system, making it easily extensible.

 

 1. Server Architecture

 The server is a program that tabulates votes for various elections. Each client is a program that allows a human user (voter) to cast a vote in one (or more) of those elections. Each election is identified by a unique name and has associated with it a set of candidates.

When put into actual service, the server is expected to reside on some computer with a well-known network address. Computers running the client would communicate with the server over a network. For example, each voter might have a laptop (or a cellular phone!) on which the client has been installed. The voter's computer communicates with the server in order to cast votes on behalf of the voter.  You will be implementing this network connectivity in a later phase; for now, you will begin by building the GUIs.

1.1 Server Specifications

When the server is started, it reads an election file that contains

The election file is formatted as a sequence of lines. Each line is a list of comma-separated words or phrases; the first element of the list is taken to be the name of an election, with the names of candidates appearing as the subsequent elements on that line. For example, a file containing the 2 lines

Composer of the year, Stephen Sondheim, Andrew Lloyd Weber, Leonard Bernstein
Best name for CU faculty-owned sailboat, Circe, Prof@Large, Wave Train, Sea Fever

defines two elections. The first election is named "Composer of the year" and there are three candidates ("Stephen Sondheim", "Andrew Lloyd Weber", and "Leonard Bernstein"). The second election is named "Best name for CU faculty-owned sailboat" and it has four candidates ("Circe", "Prof@Large", "Wave Train", and "Sea Fever").

You should create an election file and include it in your project.  Call it ElectFile.txt.

A server management interface, accessed through a GUI, allows a person called an election official to determine the number of votes that have been cast for each candidate. This server management interface also allows the election official to declare an election to be closed, in which case the GUI displays the vote counts for each candidate in the named election, and to declare an election to be open, in which case the vote count for every candidate in the named election to be reset to 0. Notice that an election, at any given time, is either open or closed. Initially, all elections are closed.

The GUI for the server should have the following components and capabilities:

·        Election List – a list (JList) for viewing elections, along with the election status (open or closed.  The election list displays a list of the names of all elections.

o       Example: the list of elections might be “Composer of the year (CLOSED)”, “Best sailboat name (OPEN)”.

·        Candidate List - a list of candidates for the selected election, along with the number of votes for each candidate.  Whenever a new election is chosen on the election list, the candidate list should be updated with the candidates for that election.

o       Example: if the election is “Composer of the year” from above, the first line of the candidate list might be “Stephen Sondheim     10”, indicating that Stephen Sondheim has 10 votes.

·        A button to open the selected election.  This will immediately set the status of the selected election in the election list to OPEN.  Votes for all candidates in that election should be set to zero.  The election list should display the updated status of the election.  This button should be disabled when the selected election is open, and enabled when the selected election is closed.

·        A button to close the selected election.  This will immediately set the status of the selected election in the election list to CLOSED.  Votes for all candidates in that election remain as they are (they are not reset to zero).  The election list should display the updated status of the election.  This button should be disabled when the selected election is closed, and enabled when the selected election is open.

·        A refresh button.  This will be used in the next assignment, when we connect the client and server program through networking.  For now, just have a message like “refreshing election <election name>” be printed to the console, where <election name> is the name of the currently chosen election.

It may be difficult to test the effects of the open and close buttons on vote tallies, since we don’t yet have a way to vote for candidates.  Therefore, you should add another button, such as “test vote”, which casts a vote for the selected candidate.  Since you may not vote for candidates in a closed election, this button should only increase a candidate’s vote count if the election is open; it should not affect the vote tallies in a closed election.  These facts suggest that you may want to have a vote() function in your code, which might take in an Election and a Candidate, and only increases the candidate’s vote count if the election is open.  You could have it return a Boolean indicating whether or not the vote was successfully cast (these are just suggestions).

 

2. Client Architecture

The client program will eventually allow us to connect to the server, view elections and candidates (though not the votes for the candidate), and cast votes.  When the client is first started, the GUI should appear. 

After future assignments, the client should have the following functionality: the user should be able to connect to the server, at which point a username/password login dialog box pops up, asking the user for her username and password.  The client will send this information to the server for verification.  Once connected and verified by the server, the server will send its list of elections and candidates, which the client will display.  The user will be able to browse the elections and their candidates, and vote for candidates.

Since we won’t be doing any networking yet, this functionality will have to wait. The dialog box should just close once the user enters her username and password.  We also won’t be able to cast votes yet.

2.1 Client Specifications

The GUI for the client should have the following components and capabilities:

·        Election List – a list (JList) for viewing elections.  The election status is not shown here, unlike in the server GUI.

·        Candidate List - a list of candidates for the selected election.  Whenever a new election is chosen on the election list, the candidate list should be updated with the candidates for that election.

·        A “Connect” button to connect to the server.  When this button is pressed, a dialog box pops up, prompting the user for his username and password.  This dialog box should have a JTextField for the username, a JPasswordField for the password (this is like a text field, but doesn’t show the actual characters of the password), an “OK” button, and a “Cancel” button.  For now, after the OK button is pressed, print the username and password to the console, and close the dialog box.  After the Cancel button is pressed, just close the dialog box.

o       After the client is connected, you should disable the “Connect” button.  When the client disconnects, you should enable this button.  You should save the state of the connection (connected or disconnected) somewhere in your code.

·        A “Disconnect” button to disconnect from the server.  For now, just print a message to console whenever this button is pressed, such as “Disconnected from server”.

o       When the client is not connected to the server (such as when the program is started), this button should be disabled.  When the client is connected, this server should be enabled.

o       When the client disconnects, the election list and candidate list should both be emptied.

·        A button to vote for the selected candidate.  This button should only be enabled when the client is connected to the server; it should be disabled when not connected.  When this button is pressed, pop up a dialog box that says something like “Vote cast for <candidate’s name>”.  You should take a look at the JOptionPane.showMessageDialog() method to do this.

For now, when the Connect button is pressed, read in the ElectFile.txt file and fill the election list and candidate list with the proper information.  This will allow you to test the functionality of the lists and the vote button.

 

 3. Design Priorities

 The software you design should show good class structure and be easy to extend.  Good documentation, good structure, clean abstractions, and straightforward control flow all contribute to such extensibility. You should also make proper use of Java’s many data structures, such as hash tables, linked lists, etc. (if and where you think you need them).  Think about what classes and class structure you’ll need beforehand, and what those classes should do.  For example, you may want an Election class, since you will be dealing with elections.  You might then ask: what should an Election object hold, and what functionality should it have?

 

4. General Specifications

 

5. Submission

You should send your project submission to my email address (ejk16@cornell.edu).  Please put all submitted files in a .zip file whose name has the format "proj1_<netid>.zip", where <netid> is the netid of one of your group members.  For example, I would submit a file called "proj1_ejk16.zip".

Your zip file should contain the following files (at least):

 

6. Partners

Read the Partners section of the Syllabus for rules on partners.  Briefly, for this assignment you may work alone, or in a group of up to 3 members total.  Personally, I recommend a group size of 2; however, if you do decide to have a group of 3, make sure each member understands the code of each other member.

 

7. Extra Credit

For extra credit, add functionality to the server GUI to add and delete elections, and to add and delete candidates in an election.  When your program is closed, those changes should be updated in your ElectFile election file, so that server can load the new set of elections and candidates the next time it is started .  Make sure that all other parts of the server GUI function normally, though!