Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Programm territories and their populations. The data for the states is stored in the file StatePops.txt'. Assume you do not know how many states
Java
Programm territories and their populations. The data for the states is stored in the file StatePops.txt'. Assume you do not know how many states are in the file (ie. your program should work with any length file). Use a pair of parallel ArrayLists to store the states (Strings) and their populations (Integers). Create the following methods: 1. readFile - pass in both ArrayLists, read the values from the file and add the states to one list and the populations to the other (be sure to keep them in the same order). 2. sortStates - pass in both ArrayLists, sort the parallel lists alphabetically by state name (note - you can't compare strings using relational operators, only string functions). 3. sortPopulation - pass in both ArrayLists, sort the lists by population (from low-high). 4. displayStates - pass in both ArrayLists, display each state and its population. 5. totalSum - pass in the populations ArrayList, calculate and return the sum. 6. population Greater pass in both ArrayLists, prompt the user to enter a population, then display all states and their populations that have a larger population than what the user entered. 7. menu - display the menu options below. Menu - Repeat the menu until the user quits. State Stats 1. Display Sorted States 2. Display Sorted Populations 3. Display Total US Population 4. Display States with Population Greater Than 5. Quit Notes: 1. Do not throw exceptions from main. Handle the exception in your readFile method. 2. Use a pair of ArrayLists, not arrays. 3. Read in the file when the program starts (readFile should only be called once). 4. Do not use global variables. 5. Display all populations formatted with the thousand's separator (ex. State 10,987,654) (See Lecture 1B). 6. Check all user input for validity. Use the CheckInput class given on Beachboard. 7. Use Javadocs to document all functions with a description, parameters, and return values. Add brief comments to describe your code. 8. Place your names, the date, and a description of the program in a comment block at the top of your program. 9. You cannot use relational operators to compare strings. Instead, use the string function compare To or compare TolgnoreCase when sorting the state names. The compare To function returns a 0 if the two strings are the same, a negative value if they are in order, and a positive value if they are out of order. Ex. if ( list.get(i).compareTo ( list.get(i + 1)) > 0) { 10. Use the following sorting algorithm for your sorts. You will need to modify it to work for your program (ie. change it to strings for sorting the state names, and/or add in the extra swaps for the parallel array). You won't be able to use Collections.sort(), it will not work for the parallel arrays. public static void sort ( ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started