Question: C:> java BloodBank (no cmd args. filenames hardcoded ) Blood is a scarce resource everywhere. Blood banks keep records of which donors have which blood

C:\> java BloodBank (no cmd args. filenames hardcoded) 

Blood is a scarce resource everywhere. Blood banks keep records of which donors have which blood type. U.S. presidents travel with a supply of their own blood kept in a miniature operating room on Air Force One in case that plane comes under attack. This program processes a presidential bloodbank database. Your solution must read a list of entries consisting of a blood type followed by the presidents who share that type.

Starter File: BloodBank.java

The file type2pres.txt represents a mapping of a blood type to the list of presidents who have that blood type. The tokens on each line are comma delimited. The file type2pres.txt contains:

A+,G.W.Bush,B.H.Obama,J.F.Kennedy A-,A.Lincoln,U.S.Grant,L.B.Johnson,G.A.Ford,W.J.Clinton B+,T.L.Hoffman,F.D.Roosevelt,J.A.Garfield O,R.M.Nixon,G.Cleveland,C.A.Arthur B-, 

ou can easily split a comma delimited line into an array of tokens like this:

String[] tokens = infile.readLine().split(","); 

You can even use the Arrays.asList() method to put those tokens diretly into an ArrayList. This method converts a plain array to a List which is suitable to initialize an ArrayList.

ArrayList presidents = new ArrayList( Arrays.asList( infile.readLine().split(",") ) ); 

STEP #1: Generate a map from bloodtype (the key) to a list of presidents (the value). Print to the screen sorted by bloodtype, and list the presidents alphabetically on the line. SEE OUTPUT.

STEP #2: Generate an inverse mapping where each president's name is a unique key and his bloodtype is the value. Print that map sorted alphabetically by president. SEE OUTPUT.

Java Starter file:

import java.io.*; import java.util.*; public class BloodBank { public static void main(String[] args) throws Exception { BufferedReader infile = new BufferedReader( new FileReader( "type2pres.txt" ) ); TreeMap> type2President = new TreeMap>(); } // MAIN } // BLOODBANK 

Sample Output:

C:\> java BloodBank (no cmd args. filenames hardcoded) Blood is a scarce

C chegg study IGuided Sc x Tim Hoffman) C people.cs pitt edu hoffmant/S17-401/ 0, R.M.Nixon, G. Cleveland, C.A.Arthur CS 101 S 17 You can easily split a a Led line into an array of tokens like this String tokens infile. readline split Back MAIN PAGE You can even wee the Arrave.aaList0 method to put thoee tokena diretly into an ArrayList. Thie method converte a plain array to s List which is suitable to initialize an ArrayList. Array List string presidents new ArrayList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!