Project2
COP3538 Project 2 – Stacks and Priority Queues
Liu University of North Florida 1
Due Date: Friday, 6/14/2019 11:59 PM
Turn in:
Submit the zipped Eclipse program including at least Project2.java, Stack.java,
PriorityQueue.java, State.java and States2.csv. The zip file should be named
name>_Project2.zip (for example, Liu_Project2.zip). The program should be well documented
in the format of doc comments in Java. Detailed formats are found at
http:
www.oracle.com/technetwork/articles/java/index XXXXXXXXXXhtml.
Requirements:
1. Reuse your State class from Project 1 (modify it if necessary)
2. Create a class named Stack that will implement a stack of state objects using a singly linked
list. Support the following methods.
a. Constructor that creates the stack.
. A push method to push a state on the stack
c. A pop method to pop a state off the stack and return it.
d. A printStack method to print the stack, see the example.
e. An isEmpty method that returns true if the stack is empty, false otherwise
f. An isFull method that always returns false
3. Create a class named PriorityQueue that implements a priority queue of state objects using
an a
ay, based on population, highest population is the highest priority. Support the
following methods:
a. Constructor that creates the stack a
ay based on a size provided.
. An insert method to insert a state into the queue.
c. A remove method to remove a state from the front of the queue and return it.
d. A printQueue method to print the queue in priority order, see the example.
e. An isEmpty method that returns true if the queue is empty, false otherwise
f. An isFull method that returns true if the queue is full, false otherwise
4. Create a class named Project2 that will:
a. Read the csv file (States2.csv) of states and create a single stack of state objects
containing states from regions South Pacific, West, and Middle Atlantic (discard
any states not in those regions, do not modify the input file.).
. Print the stack starting with the top of the stack.
c. Create three priority queues, one for each region.
d. Pop states off the stack one at a time and insert them into the appropriate priority
queue until the stack is empty.
e. Print all three priority queues in this order: South Pacific, West, then Middle
Atlantic.
f. Remove items from the South Pacific priority queue, one at a time, and push them on
the stack.
g. Remove items from the West priority queue, one at a time, and push them on the
stack.
COP3538 Project 2 – Stacks and Priority Queues
Liu University of North Florida 2
h. Remove items from the Middle Atlantic priority queue, one at a time, and push them
on the stack.
i. Print the stack on last time, then exit the program
The queues and the stack should be printed in the following format:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
Florida XXXXXXXXXXTallahassee XXXXXXXXXXFL XXXXXXXXXX,552, XXXXXXXXXXSouth XXXXXXXXXX
Arkansas XXXXXXXXXXLittle Rock XXXXXXXXXXAR XXXXXXXXXX,959, XXXXXXXXXXSouth XXXXXXXXXX
Alabama XXXXXXXXXXMontgomery XXXXXXXXXXAL XXXXXXXXXX,833, XXXXXXXXXXSouth XXXXXXXXXX
Provide comments in this form for the State, Stack, and PriorityQueue
classes:
Comments for the class:
**
* Detailed description of the class.
*
* @author
* @version
*/
Public method comments:
**
* Description of the purpose of the method, the meaning of the
* input parameters (if any) and the meaning of the return values * (if any).
*
* @param parameter description of the parameter (one for each)
* @return description of the return value
*/
Provide comments in this form for the Project2 class.
**
* COP 3538: Project 2 – Stacks and Priority Queues
*
* Description of the class using as many lines as needed
* with
between paragraphs. Including descriptions of the
* input required and output generated.
*
* @author
* @version
*/
public class Project2
{
COP3538 Project 2 – Stacks and Priority Queues
Liu University of North Florida 3
Example:
COP3538 Project 2
Instructor: Xudong Liu
Stacks and Priority Queues
Enter the file name: States2.csv
There were 22 state records put on the stack.
Stack Contents:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
Wyoming XXXXXXXXXXCheyenne XXXXXXXXXXWY XXXXXXXXXX, XXXXXXXXXXWest XXXXXXXXXX
West Virginia XXXXXXXXXXCharleston XXXXXXXXXXWV XXXXXXXXXX,805, XXXXXXXXXXMiddle Atlantic 3
Washington D.C XXXXXXXXXXWashington D.C. DC XXXXXXXXXX, XXXXXXXXXXMiddle Atlantic 0
. . .
South Pacific Priority Queue Contents:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
Guam XXXXXXXXXXHagatna XXXXXXXXXXGU XXXXXXXXXX, XXXXXXXXXXSouth Pacific XXXXXXXXXX
American Samoa XXXXXXXXXXPago Pago XXXXXXXXXXAS XXXXXXXXXX, XXXXXXXXXXSouth Pacific XXXXXXXXXX
. . .
West Priority Queue Contents:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
California XXXXXXXXXXSacramento XXXXXXXXXXCA XXXXXXXXXX,332, XXXXXXXXXXWest XXXXXXXXXX
Washington XXXXXXXXXXOlympia XXXXXXXXXXWA XXXXXXXXXX,971, XXXXXXXXXXWest XXXXXXXXXX
. . .
Middle Atlantic Priority Queue Contents:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
New York XXXXXXXXXXAlbany XXXXXXXXXXNY XXXXXXXXXX,542, XXXXXXXXXXMiddle Atlantic 27
Pennsylvania XXXXXXXXXXHa
isburg XXXXXXXXXXPA XXXXXXXXXX,807, XXXXXXXXXXMiddle Atlantic 18
. . .
Stack Contents:
State Name XXXXXXXXXXCapital City State A
State Population Region XXXXXXXXXXUS House Seats
-------------------------------------------------------------------------------------------------------
Washington D.C XXXXXXXXXXWashington D.C. DC XXXXXXXXXX, XXXXXXXXXXMiddle Atlantic 0
Delaware XXXXXXXXXXDover