Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Data Structures Project that I'm struggling with and need help. Some specification and a MUST.. Do not use Java-provided classes (List, Collections,

This is a Data Structures Project that I'm struggling with and need help. Some specification and a MUST..Do not use Java-provided classes (List, Collections, Comparator) or methods (Collections.sort)..You have to implement the classes State,Stack, Priority and the Project2 classes which reads from the file. Please use these specific details and all prinnt statements as indicated in the project and show the javadoc comments.

Here is the project:

COP3538 Project 2 Stacks and Priority Queues

Turn in:

Submit the zipped Eclipse program including at least Project2.java, Stack.java, Priority.java,

State.java and States2.csv. The zip file should be named _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-137868.html.

Requirements:

1. Reuse your State class from Project 1 (correct it if necessary)

2. Create a class named Stack that will implement a stack of state objects using an array.

Support the following methods.

a. Constructor that creates the stack array based on a size provided.

b. 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 returns true if the stack is full, false otherwise

3. Create a class named Priority that implements a priority queue of state objects using an

array, based on population, highest population is the highest priority. Support the following

methods:

a. Constructor that creates the stack array based on a size provided.

b. 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, West, and Midwest that data (discard any

states not in those regions, do not modify the input file.).

b. 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, West, then Midwest.

f. Remove items from the South 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.

h. Remove items from the Midwest 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

i. Print the stack, then exit the program

The queues and the stack should be printed in the following format:

Stack Contents: or South Priority Queue Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

Florida Tallahassee FL 19,552,860 South 27

Arkansas Little Rock AR 2,959,373 South 4

Alabama Montgomery AL 4,833,722 South 7

Provide comments in this form for the State, Stack, and Priority classes:

Comments for the class:

/**

* Detailed description of the class.

*

* @author <your name>

* @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 <your name>

* @version <the date you last modified the program>

*/

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 33 state records put on the stack.

Stack Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

Wyoming Cheyenne WY 582,658 West 1

Wisconsin Madison WI 5,742,713 Midwest 8

Washington Olympia WA 6,971,406 West 10

. . .

South Priority Queue Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

Florida Tallahassee FL 19,552,860 South 27

Georgia Atlanta GA 9,992,167 South 14

. . .

West Priority Queue Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

California Sacramento CA 38,332,521 West 53

Washington Olympia WA 6,971,406 West 10

. . .

Midwest Priority Queue Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

Illinois Springfield IL 12,882,135 Midwest 18

Ohio Columbus OH 11,570,808 Midwest 16

. . .

Stack Contents:

State Name Capital City State Abbr State Population Region US House Seats

-------------------------------------------------------------------------------------------------------

North Dakota Bismarck ND 723,393 Midwest 1

South Dakota Pierre SD 844,877 Midwest 1

. . .

Here is the State class, it needed to be corrected:

import java.util.Comparator;

/**

*

* This class stores the information about a state.

*

* It also facilitates the sorting by

*

* state name, capital, abbreviation, population, region and house seats

*

* and display the information contained in this class.

*

* @author your name

*

* @version September 13, 2017

*

*/

public class State

{

private String stateName;

private String capitalCity;

private String stateAbbreviation;

private int statePopulation;

private String region;

private int houseSeats;

/**

*

* Default constructor

*

*/

public State()

{

}

/**

*

* Constructor with fields

*

* @param stateName

*

* @param capitalCity

*

* @param stateAbbreviation

*

* @param statePopulation

*

* @param region

*

* @param houseSeats

*

*/

public State(String stateName, String capitalCity, String stateAbbreviation, int statePopulation, String region, int houseSeats)

{

super();

this.stateName = stateName;

this.capitalCity = capitalCity;

this.stateAbbreviation = stateAbbreviation;

this.statePopulation = statePopulation;

this.region = region;

this.houseSeats = houseSeats;

}

/**

*

* The getter method for state name

*

* @return stateName

*

*/

public String getStateName()

{

return stateName;

}

/**

*

* The setter method for stateName

*

* @param stateName

*

*/

public void setStateName(String stateName)

{

this.stateName = stateName;

}

/**

*

* The getter method for capital city

*

* @return capitalCity

*

*/

public String getCapitalCity()

{

return capitalCity;

}

/**

*

* The setter method for capitalCity

*

* @param capitalCity

*

*/

public void setCapitalCity(String capitalCity)

{

this.capitalCity = capitalCity;

}

/**

*

* The getter method for state abbreviation

*

* @return stateAbbreviation

*

*/

public String getStateAbbreviation()

{

return stateAbbreviation;

}

/**

*

* The setter method for stateAbbreviation

*

* @param stateAbbreviation

*

*/

public void setStateAbbreviation(String stateAbbreviation)

{

this.stateAbbreviation = stateAbbreviation;

}

/**

*

* The getter method for state population

*

* @return statePopulation

*

*/

public int getStatePopulation()

{

return statePopulation;

}

/**

*

* The setter method for statePopulation

*

* @param statePopulation

*

*/

public void setStatePopulation(int statePopulation)

{

this.statePopulation = statePopulation;

}

/**

*

* The getter method for region

*

* @return region

*

*/

public String getRegion()

{

return region;

}

/**

*

* The setter method for region

*

* @param region

*

*/

public void setRegion(String region)

{

this.region = region;

}

/**

*

* The getter method for the US house seats

*

* @return houseSeats

*

*/

public int getHouseSeats()

{

return houseSeats;

}

/**

*

* The setter method for the US house seats

*

* @param houseSeats

*

*/

public void setHouseSeats(int houseSeats)

{

this.houseSeats = houseSeats;

}

/**

*

* This method display the members of this class in formatted way

*

*/

public void display()

{

System.out.println("State Name: " + stateName);

System.out.println("Capital City: " + capitalCity);

System.out.println("State Abbr: " + stateAbbreviation);

System.out.println("State Population: " + statePopulation);

System.out.println("Region: " + region);

System.out.println("US House Seats: " + houseSeats);

}

@Override

public String toString()

{

return stateName + " " + capitalCity + " " + stateAbbreviation + " " + statePopulation + " " + region + " " + houseSeats;

}

public static Comparator stateNameComparator = new Comparator()

{

}

}

}

And this is the State2.csv file to be read from:

State,Capital,Abbreviation,Population,Region,US House Seats

Alabama,Montgomery,AL,4833722,South,7

Alaska,Juno,AK,735132,West,1

Arizona,Phoenix,AZ,6626624,Southwest,9

Arkansas,Little Rock,AR,2959373,South,4

California,Sacramento,CA,38332521,West,53

Colorado,Denver,CO,5268367,West,7

Connecticut,Hartford,CT,3596080,New England,5

Delaware,Dover,DE,925749,Middle Atlantic,1

Florida,Tallahassee,FL,19552860,South,27

Georgia,Atlanta,GA,9992167,South,14

Hawaii,Honolulu,HI,1404054,West,2

Idaho,Boise,ID,1612136,West,2

Illinois,Springfield,IL,12882135,Midwest,18

Indiana,Indianapolis,IN,6570902,Midwest,9

Iowa,Des Moines,IA,3090416,Midwest,4

Kansas,Topeka,KS,2893957,Midwest,4

Kentucky,Frankfort,KY,4395295,South,6

Louisiana,Baton Rouge,LA,4625470,South,6

Maine,Augusta,ME,1328302,New England,2

Maryland,Annapolis,MD,5928814,Middle Atlantic,8

Massachusetts,Boston,MA,6692824,New England,9

Michigan,Lansing,MI,9895622,Midwest,14

Minnesota,St Paul,MN,5420380,Midwest,8

Mississippi,Jackson,MS,2991207,South,4

Missouri,Jefferson City,MO,6044171,Midwest,8

Montana,Helena,MT,1015165,West,1

Nebraska,Lincoln,NE,1868516,Midwest,3

Nevada,Carson City,NV,2790136,West,4

New Hampshire,Concord,NH,1323459,New England,2

New Jersey,Trenton,NJ,8899339,Middle Atlantic,12

New Mexico,Santa Fe,NM,2085287,Southwest,3

New York,Albany,NY,19651127,Middle Atlantic,27

North Carolina,Raleigh,NC,9848060,South,13

North Dakota,Bismarck,ND,723393,Midwest,1

Ohio,Columbus,OH,11570808,Midwest,16

Oklahoma,Oklahoma City,OK,3850568,Southwest,5

Oregon,Salem,OR,3930065,West,5

Pennsylvania,Harrisburg,PA,12773801,Middle Atlantic,18

Rhode Island,Providence,RI,1051511,New England,2

South Carolina,Columbia,SC,4774839,South,7

South Dakota,Pierre,SD,844877,Midwest,1

Tennessee,Nashville,TN,6495978,South,9

Texas,Austin,TX,26448193,Southwest,36

Utah,Salt Lake City,UT,2900872,West,4

Vermont,Montpelier,VT,626630,New England,1

Virginia,Richmond,VA,8260405,Middle Atlantic,11

Washington,Olympia,WA,6971406,West,10

West Virginia,Charleston,WV,1854304,Middle Atlantic,3

Wisconsin,Madison,WI,5742713,Midwest,8

Wyoming,Cheyenne,WY,582658,West,1

It would be a good help implementing all the classes in the requirement

Thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions