Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help finishing this code, it just reads in a couple files and sorts them in different ways, and I have attached the

I need some help finishing this code, it just reads in a couple files and sorts them in different ways, and I have attached the link to the three files in the directions. I have completed step #1 and the code is at the bottom so far.

STEP #1 - Read the state2Presidents.txt file into a map such that when you print the map out the rows are sorted vertically by state and each row's set of presidents on that row are sorted alphabetically (Link for help for step 1 and step 2: STEP#1)

Step #2 - Print the inverse of the state2presidents map. List each president on his own line with the state where he was born. You do not have to explicitly store this inversion into a map but you must generate the following output exactly. The lines are sorted by president alphabetically. You may Use the allPresidents.txt file in any way needed for this step but be aware the allPresidents.txt file contains all the presidents of the US - and some of them do not have a birth state associated with them since they were not born before the states were formed. You are only to list those presidents who have a birth state.

Step #3 - Print a sorted list of presidents who have no birth state associated with them. These presidents were actually born on this continent but were born before the states were created.

Step #4 - Print a sorted list of states that have no president born in them. You may use the allStates.txt file for this.

Here is the code I have so far:

import java.util.*;

import java.io.*;

public class Potus { public static void main( String[] args ) throws Exception { BufferedReader infile1 = new BufferedReader( new FileReader("state2Presidents.txt") ); BufferedReader infile2 = new BufferedReader( new FileReader("allPresidents.txt") ); BufferedReader infile3 = new BufferedReader( new FileReader("allStates.txt") );

// YOUR CODE HERE TO DECLARE MAPS OR SETS TO HOLD THE DATA OF THESE THREE INPUT FILES // ######### STEP #1: READ INFILE 1 INTO A MAP AND PRINT IT FORMATTED. worth 70% ########## // YOUR CODE HERE TO READ INFILE1 INTO A MAP AND PRINT IT TreeMap> state2Presidents = new TreeMap>(); while (infile1.ready()) // using a BufferedReader line at a time { String[] tokens = infile1.readLine().split("\\s+"); String state = tokens[0]; TreeSet presidents = new TreeSet(); for (int i = 1 ; i

// ############ STEP #3: PRINT THE NAMES OF PRESIDENTS BORN BEFORE STATES FORMED worth 10% ########## System.out.println(); // LEAVE THIS HERE TO PUT A BLANK LINE BETWEEN SECTIONS // YOUR CODE HERE TO PRINT THE NAMES OF ALL PRESIDENTS BORN BEFORE STATES FORMED

// ###STEP #4 PRINT THE NAME(S) OF ANY STATE(s) WHICH HAD NO PRESIDENT BORN IN THEM worth 5% ####### System.out.println(); // LEAVE THIS HERE TO PUT A BLANK LINE BETWEEN SECTIONS

// YOUR CODE HERE TO PRINT THE NAME(S) OF ANY STATE(s) WHICH HAD NO PRESIDENT BORN IN THEM

} // END MAIN

// - - - - - - - - - - - H E L P E R M E T H O D S D O W N H E R E - - - - - - - - - -

} // END POTUS CLASS

OUTPUT:

After Step 1

image text in transcribed

After Step 2

image text in transcribed

After Step 3

image text in transcribed

After Step 4

image text in transcribed

Arkansas Clinton California Nixon Connecticut Bush GW Georgia Carter Hawaii Obama Illinois Reagan Iowa Hoover Kentucky Lincoln Massachusetts Bush GHW Kennedy Missouri Truman Nebraska Ford New Hampshire Pierce New Jersey Cleveland New York Fillmore Roosevelt F Roosevelt T VanBuren North Carolina Johnson A Polk Ohio Garfield Grant Harding Harrison B Hayes McKinley Taft Pennsylvania Buchanarn Texas Eisenhower Johnson I Vermont Arthur Coolidge Virginia Taylor Tyler Wilson Arkansas Clinton California Nixon Connecticut Bush GW Georgia Carter Hawaii Obama Illinois Reagan Iowa Hoover Kentucky Lincoln Massachusetts Bush GHW Kennedy Missouri Truman Nebraska Ford New Hampshire Pierce New Jersey Cleveland New York Fillmore Roosevelt F Roosevelt T VanBuren North Carolina Johnson A Polk Ohio Garfield Grant Harding Harrison B Hayes McKinley Taft Pennsylvania Buchanarn Texas Eisenhower Johnson I Vermont Arthur Coolidge Virginia Taylor Tyler Wilson

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

What is the crystal form of ice and how is it exhibited?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago