Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, This is a Data Structure project that I am working on... I have to submit the Eclipse program including at least Project3.java, Stack.java, Queue.java,

Hi,

This is a Data Structure project that I am working on...

I have to submit the Eclipse program including at least Project3.java, Stack.java, Queue.java, State.java.

The Scanner input ask to Enter the file name

COP3538 Project 3 Linked lists

Requirements:

1. Reuse your State class from Project 1 (corrected 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.

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 always returns false

3. Create a class named Queue that implements a queue (double-ended queue, actually) of state

objects using a doubly linked list. Support the following methods:

a. Constructor that creates the queue.

b. An insertEnd method to insert a state at the end of the queue.

c. An insertFront method to insert a state at the front of the queue.

d. A removeEnd method to remove a state from the end of the queue and return it.

e. A removeFront method to remove a state from the front of the queue and return it.

f. A findDelete method to find a state in the queue by state name, and delete it from the

queue. Return true if it was found and deleted and false otherwise.

g. A printQueue method to print the queue in order front to end

h. An isEmpty method that returns true if the queue is empty, false otherwise

i. An isFull method that returns false always

4. Create a class named Project3 that will:

a. Read a file (csv) of states and create a single stack of state objects containing states

from regions New England, Middle Atlantic, and South (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 a queue. Pop items from the stack, one at a time, and insert them to the queue:

insert the first popped state in the front, the second popped state at the end, the third

popped state at the front, the fourth popped state at the end, and so forth.

d. Print the queue.

e. Delete states Massachusetts, New Hampshire, Rhode Island, Maryland, New Jersey,

Pennsylvania, Alabama, Kentucky, and North Carolina in the queue and print the

queue again.

f. Remove items from the queue, one at a time, and push them on the stack. Remove

one state from the front, then one from the back, then the front, then the back, and so

forth.

g. Print the stack, then exit the program

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

Stack Contents: or Queue Contents:

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

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

Connecticut Hartford CT 3,596,080 New England 5

Florida Tallahassee FL 19,552,860 South 27

Arkansas Little Rock AR 2,959,373 South 4

Provide comments in this form for the State, Stack, and Queue 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 Project3 class.

/**

* COP 3538: Project 3 Linked lists

*

* 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 Project3

{

Example:

COP3538 Project 3 Xudong Liu

Linked lists

Enter the file name: States3.csv

There were 23 state records put on the stack.

Stack Contents:

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

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

West Virginia Charleston WV 1,854,304 Middle Atlantic 3

Virginia Richmond VA 8,260,405 Middle Atlantic 11

. . .

Arkansas Little Rock AR 2,959,373 South 4

Alabama Montgomery AL 4,833,722 South 7

Queue Contents:

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

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

Alabama Montgomery AL 4,833,722 South 7

Connecticut Hartford CT 3,596,080 New England 5

. . .

Delaware Dover DE 925,749 Middle Atlantic 1

Arkansas Little Rock AR 2,959,373 South 4

Queue Contents:

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

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

Connecticut Hartford CT 3,596,080 New England 5

Florida Tallahassee FL 19,552,860 South 27

. . .

Delaware Dover DE 925,749 Middle Atlantic 1

Arkansas Little Rock AR 2,959,373 South 4

Stack Contents:

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

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

Virginia Richmond VA 8,260,405 Middle Atlantic 11

West Virginia Charleston WV 1,854,304 Middle Atlantic 3

. . .

Arkansas Little Rock AR 2,959,373 South 4

Connecticut Hartford CT 3,596,080 New England 5

Here is the State Class ( it needed to be corrected)

/**

*

* 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 States3.csv file to 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

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

Step: 3

blur-text-image

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago