Mail sorter

the MailSorter class is part of a post office machine that scans addresses on envelopes looking for a 5-digit zipcode and 2-letter state abbreviation. Because these are often hand-written, there are often errors.

MailSorter’s job is either


The MailSorter class has several functions that are already written for you:

isAthruZ( char candidate ) – returns true if candidate is A-Z (a capital letter)

is0thru9( char candidate ) – returns true if candidate is 0-9 (a digit)

IsState( String candidate ) – returns true if candidate is a valid 2-letter state name

StateFromZip( String zip ) – returns 2-letter state name for the zip code

You must write the sort(String text) function, which will study the text, and either call


To be confident, the a 2-letter state name must come before the 5-digit zipcode and the zipcode must be in the state.

Pre-condidtion: the text argument to the sort function is upper case.

The sort function might be called with any of these strings:

"JOHN SMITH 100 ELM ST RALEIGH, NC 27605" (confident)

"SUSAN SMITH 27609 OAK DR, RALEIGH NC" (bad data, ZIP does not follow state)

"TERRY SMITH 10 PINE ST FORT SMITH MM 27605" (bad data, unknown state name)

"RALPH SMITH 10 CHERRY LN RALEIGH NC 99999" (bad data, zip not in state)

public class MailSorter {
	private boolean isAthruZ( char candidate ) { provide elsewhere }
	private boolean is0thru9( char candidate ) { provided elsewhere }
	private boolean isState( String candidate ) { provided elsewhere }
	private String stateFromZip( String zipcode ) { provided elsewhere }
	private void route( String state, String zip ) { provided elsewhere }
	private void manual() { provided elsewhere }
	public sort(String text) {