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.

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-, 

You 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.

Starter File: BloodBank.java

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" ) ); } // MAIN } // BLOODBANK 

SAMPLE OUTPUT CAPTURE

Command Prompt CNUs erst im Desktop an java an A+ B. H. Obama G. W. Bush J. F. Kennedy A. Lincoln G.A. Ford L. B. Johnson U. S. Grant W. J. Clint on B+ F. D. Roosevelt J. A. Garfield T. L. Hoffman C. A. Arthur G.Cleveland R.M.Nixon A. Lincoln B. H. alma A+ C. A. Arthur F. D. Roosevelt B+ G. A. Ford G. Cleveland G. W. Bush A+ J. A. Garfield B+ J. F. Kennedy A+ L. B. Johnson R. M. Nixon T. L. Hoffman B+ U.S. Grant W. J. Clinton C: Users tim Desktop an

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!