Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

You are writing a program (PostalCode.java) for Canada Post to help members of the Post Office in Alberta route mail.

dpatel23
dpatel23 


Your program will take the entire address of a parcel and route it in the following manner (see the map below): • All parcels destined for Alberta should be sent to the Central Post Office • All parcels destined for provinces or territories bordering on Alberta should be sent to the Truck Depot • All parcels destined for provinces or territories which do not border Alberta should be sent to the Airport Addresses contain several lines of detailed text about the recipient’s address before the postal code. Your program should continue reading in text until a valid Canadian postal code is entered (hint: this requires a sentinel loop). Once the postal code is read, the program should route the parcel to the appropriate location (Central Post Office, Truck Depot, or Airport). A valid Canadian postal code is six characters long, but may contain an extra space between the first set of three and second set of three characters. Canadian postal codes alternate letters and numbers, and must start with one of the letters in the map below (e.g., R3N 4Q2 or G1A2W4 are both valid postal codes). Your program must contain a few meaningful methods to manage the complexity of the problem. Focus on and test the correctness of one method before implementing the next method. For example, you may implement a method to test whether a given string is a valid Canadian postal code (this method may use a few other methods to simplify the validation process). // Returns true if the given code is a valid Canadian postal code // Otherwise returns false public static boolean isPostalCode(String code) Example 1 (user input underlined): Please enter the address: Grant MacEwan University P.O. Box 1796 Edmonton, AB T5J 2P2 This parcel should go to the Central Post Office Example 2 (user input underlined): Please enter the address: Canada Place Corporation 999 Canada Place Vancouver, British Columbia V6C3E1 This parcel should go to the Truck Depot Example 3 (user input underlined): Please enter the address: CN Tower 301 Front Street West Toronto, Ontario M5V 2T6 This parcel should go to the Airport First Letters of Canadian Postal Codes NL - A NS - B PE - C NB - E QC - G, H, J ON - K, L, M, N, P MB - R SK - S AB - T BC - V NU/NT - X YT - Y Attachments
Tags Clarifications

Answers

Java - PostalCode.java - Solution

dickersonka
dickersonka 



Attached is the solution... Attachments
PostalCode.java (3 K) Download Preview
True if postal code starts with valid letter, false otherwise */ private static boolean validateStart(String code){ //valid starting letters for postal code String[] startsWith = new String[]{"A", "B", "C", "E", "G", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "V", "X", "Y"};

screenshot.jpg (14 K) Download Preview

Screenshots
Screenshot
Purchase Answer