Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Data Structures in jave please help with this project: Requirements: 1. Cr

ID: 3869829 • Letter: U

Question

Using Data Structures in jave please help with this project:

Requirements:

1. Create a class named State that will store information about a US state and provide methods

to get, and set the data, and compare the states by several fields.

a. Fields: State Name, Capital City, State Abbreviation, State Population, Region, US

House Seats

b. Constructor

c. Get and set methods for each field

d. Compare method to compare based on State Name (expects a State object as a

parameter)

e. Method to print a state

2. Create a class named Project1 that will:

a. Read the file (csv) of states and create an array of state objects containing that data.

b. Offer the user the following options:

1) Print a state report

2) Sort by state name (using Bubble sort)

3) Sort by population (using Selection sort)

4) Sort by Region (using Insertion sort)

5) Find and print a given state (using binary search if the data is sorted by state

name, sequential search if not)

6) Quit

c. Implement the given option, then prompt again. (deal with invalid choice)

Project1 should have main and methods for each options 1-5.

d. The State report in option 1 should be in this form:

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

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

Florida Tallahassee FL 19,552,860 South 27

Pennsylvania Harrisburg PA 12,773,801 Middle Atlantic 18

Massachusetts Boston MA 6,692,824 New England 9

e. The State report in option 5 should be in this form:

State Name: Florida

Capital City: Tallahassee

State Abbr: FL

State Population: 19,552,860

Region: South

US House Seats: 27

Provide comments in this form for the State class:

COP3538 Project 1 – Array Searches and Sorts

Liu University of North Florida 2

Comments for the class:

/**

* Detailed description of the class.

*

* @author <your name>

* @version <date you last changed the class>

*/

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 Project1 class.

Comments for the class:

/**

* COP 3538: Project 1 – Array Searches and Sorts

* <p>

* Description of the class using as many lines as needed

* with <p> between paragraphs. Including descriptions of the

* input required and output generated.

*

* @author <your name>

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

*/

public class Project1

{

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

*/

COP3538 Project 1 – Array Searches and Sorts

Liu University of North Florida 3

Output Example:

COP3538 Project 1

Instructor: Xudong Liu

Array Searches and Sorts

Enter the file name: States1.csv

There were 50 state records read.

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 1

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

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

Mississippi Jackson MS 2,991,207 South 4

New Hampshire Concord NH 1,323,459 New England 2

Pennsylvania Harrisburg PA 12,773,801 Middle Atlantic 18

. . .

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 3

States sorted by Population.

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 1

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

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

Wyoming Cheyenne WY 582,658 West 1

Vermont Montpelier VT 626,630 New England 1

North Dakota Bismarck ND 723,393 Midwest 1

. . .

COP3538 Project 1 – Array Searches and Sorts

Liu University of North Florida 4

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 5

Enter the state name: Florida

Sequential search

State Name: Florida

Capital City: Tallahassee

State Abbr: FL

State Population: 19,552,860

Region: South

US House Seats: 27

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 5

Enter the state name: Canada

Sequential search

Error: State Canada not found

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 2

States sorted by State name.

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 1

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

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

COP3538 Project 1 – Array Searches and Sorts

Liu University of North Florida 5

Alabama Montgomery AL 4,833,722 South 7

Alaska Juno AK 735,132 West 1

Arizona Phoenix AZ 6,626,624 Southwest 9

. . .

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 5

Enter the state name: Kentucky

Binary search

State Name: Kentucky

Capital City: Frankfort

State Abbr: KY

State Population: 4,395,295

Region: South

US House Seats: 6

1. Print a state report

2. Sort by State name

3. Sort by Population

4. Sort by Region

5. Find and print a given state

6. Quit

Enter your choice: 23

Invalid choice enter 1-6: 0

Invalid choice enter 1-6: A

Invalid choice enter 1-6: 6

Have a good day!

Explanation / Answer

Project1.java

- - - -

import java.io.*;

import java.nio.file.Files;

import java.text.NumberFormat;

import java.util.*;

public class Project1 {

/**

* The variety of states that will be stacked

* from a document when the program is run.

*/

private static State[] states;

/**

* A case of a Scanner to peruse in

* client contribution from the support.

*/

private static last SCANNER = new Scanner(System.in);

/**

* The principle technique for our program.

*

* @param args

* Arguments entered on the summon

* line (unused).

* @throws IOException

* If a mistake happens when perusing

* a document.

*/

open static void main(String[] args) tosses IOException {

printWelcomeMessages();

readFile();

while (genuine) {

System.out.println();

attempt {

switch (printMenu()) {

case 1:

printStateReport();

break;

case 2:

sortByStateName();

break;

case 3:

sortByPopulation();

break;

case 4:

sortByRegion();

break;

case 5:

findAndPrintGivenState();

break;

case 6:

stop();

break;

default:

toss new Exception();

}

} get (Exception e) {

System.out.println();

System.out.println(&quot;Please enter a number from 1 to 6!&quot;);

}

}

}

/**

* Prints the appreciated messages to the

* comfort when the program begins.

*/

private static void printWelcomeMessages() {

System.out.println(&quot;Project 1&quot;);

System.out.println(&quot;Array Searches and Sorts&quot;);

}

/**

* Reads the record and stores it in the

* states exhibit.

*

* @throws IOException

* If a mistake happens when perusing

* the document.

*/

private static void readFile() tosses IOException {

Document record;

while (genuine) {

System.out.print(&quot;Enter the document name: &quot;);

document = new File(SCANNER.nextLine());

on the off chance that (!file.exists()) {

System.out.println();

System.out.println(&quot;That document doesn&#39;t appear to exist!&quot;);

System.out.println();

proceed;

}

break;

}

List&lt;String&gt; lines = Files.readAllLines(file.toPath());

states = new State[lines.size() - 1];

for (int I = 1; I &lt; lines.size(); i++) {

String line = lines.get(i);

String[] data = line.split(&quot;,&quot;);

String name = information[0];

String capitalCity = information[1];

String truncation = information[2];

int populace = Integer.parseInt(information[3]);

String area = information[4];

int houseSeats = Integer.parseInt(information[5]);

State = new State(name, capitalCity, truncation, populace, area, houseSeats);

states[i - 1] = state;

}

System.out.println();

System.out.println(&quot;There were &quot; + states.length + &quot; state records read.&quot;);

}

/**

* Prints the menu to the support and

* prompts the client to enter an ID.

*

* @return

* The ID that the client chooses.

*/

private static int printMenu() {

System.out.println(&quot;1. Print A State Report&quot;);

System.out.println(&quot;2. Sort By State Name&quot;);

System.out.println(&quot;3. Sort By Population&quot;);

System.out.println(&quot;4. Sort By Region&quot;);

System.out.println(&quot;5. Find And Print A Given State&quot;);

System.out.println(&quot;6. Quit&quot;);

System.out.print(&quot;Enter your decision: &quot;);

return Integer.parseInt(SCANNER.nextLine());

}

/**

* Prints the data for each

* state.

*/

private static void printStateReport() {

System.out.println();

System.out.printf(&quot;%-19s %-16s %-11s %-12s %-16s %-12s&quot;, &quot;State Name&quot;, &quot;Capital

City&quot;, &quot;State Abbr&quot;, &quot;State Population&quot;, &quot;Region&quot;, &quot;US House Seats&quot;);

System.out.println();

System.out.println(&quot;- - - - - - -

- &quot;);

for (state : states) {

System.out.println(state);

}

}

/**

* Sorts the states cluster by name.

*/

private static void sortByStateName() {

for (int external = 0; external &lt; states.length - 1; outer++) {

for (int internal = states.length - 1; inward &gt; external; inward - ) {

in the event that (states[inner].compareTo(states[inner - 1]) &gt; 0) {

State temp = states[inner];

states[inner] = states[inner - 1];

states[inner - 1] = temp;

}

}

}

System.out.println();

System.out.println(&quot;States arranged by name.&quot;);

}

/**

* Sorts the states cluster by populace.

*/

private static void sortByPopulation() {

for (int external = 0; external &lt; states.length - 1; outer++) {

int most minimal = external;

for (int internal = external + 1; inward &lt; states.length; inner++) {

in the event that (states[inner].getPopulation() &gt; states[lowest].getPopulation()) {

most minimal = inward;

}

}

if(lowest != external) {

State temp = states[lowest];

states[lowest] = states[outer];

states[outer] = temp;

}

}

System.out.println();

System.out.println(&quot;States arranged by population.&quot;);

}

/**

* Sorts the states cluster by area.

*/

private static void sortByRegion() {

int internal, external;

for (external = 1; external &lt; states.length; outer++) {

State temp = states[outer];

internal = external;

while (internal &gt; 0 &amp;&amp; states[inner - 1].getRegion().compareTo(temp.getRegion()) &gt; 0) {

states[inner] = states[inner - 1];

internal - ;

}

states[inner] = temp;

}

System.out.println();

System.out.println(&quot;States arranged by region.&quot;);

}

/**

* Prompts the client to enter the name

* of a state and show its data,

* in the event that it exists.

*/

private static void findAndPrintGivenState() {

System.out.println();

System.out.print(&quot;Enter the state name: &quot;);

String stateName = SCANNER.nextLine();

State = invalid;

for (State s : states) {

in the event that (s.getName().equalsIgnoreCase(stateName)) {

state = s;

break;

}

}

System.out.println();

in the event that (state == invalid) {

System.out.println(&quot;Error: &quot; + stateName + &quot; not found!&quot;);

return;

}

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;State Name:&quot;) + state.getName());

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;Capital City:&quot;) + state.getCapitalCity());

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;State Abbr:&quot;) + state.getAbbreviation());

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;State Population:&quot;) +

NumberFormat.getInstance().format(state.getPopulation()));

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;Region:&quot;) + state.getRegion());

System.out.println(String.format(&quot;%1$-19s&quot;, &quot;US House Seats:&quot;) + state.getHouseSeats());

}

/**

* Quits the program.

*/

private static void quit() {

System.out.println();

System.out.println(&quot;Have a decent day!&quot;);

System.exit(0);

}

}

- - - -

State.java

- -

import java.text.NumberFormat;

open class State actualizes Comparable&lt;State&gt; {

private String name;

private String capitalCity;

private String contraction;

private int populace;

private String district;

private int houseSeats;

open State(String name, String capitalCity, String contraction, int populace, String locale,

int houseSeats) {

this.name = name;

this.capitalCity = capitalCity;

this.abbreviation = contraction;

this.population = populace;

this.region = district;

this.houseSeats = houseSeats;

}

open String getName() {

return this.name;

}

open void setName(String name) {

this.name = name;

}

open String getCapitalCity() {

return this.capitalCity;

}

open void setCapitalCity(String capitalCity) {

this.capitalCity = capitalCity;

}

open String getAbbreviation() {

return this.abbreviation;

}

open void setAbbreviation(String contraction) {

this.abbreviation = contraction;

}

open int getPopulation() {

return this.population;

}

open void setPopulation(int populace) {

this.population = populace;

}

open String getRegion() {

return this.region;

}

open void setRegion(String district) {

this.region = district;

}

open int getHouseSeats() {

return this.houseSeats;

}

open void setHouseSeats(int houseSeats) {

this.houseSeats = houseSeats;

}

@Override

open int compareTo(State state) {

return state.name.compareTo(this.name);

}

@Override

open String toString() {

StringBuilder sb = new StringBuilder();

sb.append(String.format(&quot;%1$-20s&quot;, name));

sb.append(String.format(&quot;%1$-20s&quot;, capitalCity));

sb.append(String.format(&quot;%1$-10s&quot;, shortened form));

sb.append(String.format(&quot;%1$-16s&quot;, NumberFormat.getInstance().format(population)));

sb.append(String.format(&quot;%1$-20s&quot;, locale));

sb.append(String.format(&quot;%1$-20d&quot;, houseSeats));

return sb.toString();

}

}

- - - - -

State.csv

- -

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

Mississippi,Jackson,MS,2991207,South,4

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

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

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

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

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

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

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

Montana,Helena,MT,1015165,West,1

Ohio,Columbus,OH,11570808,Midwest,16

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

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

Kansas,Topeka,KS,2893957,Midwest,4

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

Texas,Austin,TX,26448193,Southwest,36

Washington,Olympia,WA,6971406,West,10

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

Alabama,Montgomery,AL,4833722,South,7

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

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

Indiana,Indianapolis,IN,6570902,Midwest,9

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

Wyoming,Cheyenne,WY,582658,West,1

Colorado,Denver,CO,5268367,West,7

Tennessee,Nashville,TN,6495978,South,9

Oregon,Salem,OR,3930065,West,5

Michigan,Lansing,MI,9895622,Midwest,14

Idaho,Boise,ID,1612136,West,2

Nebraska,Lincoln,NE,1868516,Midwest,3

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

Wisconsin,Madison,WI,5742713,Midwest,8

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

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

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

Arizona,Phoenix,AZ,6626624,Southwest,9

California,Sacramento,CA,38332521,West,53

Georgia,Atlanta,GA,9992167,South,14

Florida,Tallahassee,FL,19552860,South,27

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

Hawaii,Honolulu,HI,1404054,West,2

Kentucky,Frankfort,KY,4395295,South,6

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

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

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

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

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

Illinois,Springfield,IL,12882135,Midwest,18

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

Alaska,Juno,AK,735132,West,1

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote