Question: NEED HELP IN JAVA PLEASE PostalCode.java (USE THIS FORMAT PLEASE. CLIENT IS POSTED BELOW.) /** * SERVICE CLASS Translate ZIP code into its bar code
NEED HELP IN JAVA PLEASE
PostalCode.java (USE THIS FORMAT PLEASE. CLIENT IS POSTED BELOW.)
/** * SERVICE CLASS Translate ZIP code into its bar code representation * * @author YOUR NAME * @version 10/14/2017 */ public class PostalCode { /** * Instance variable.
* Contains the zipCode in a DDDDD-DDDD format * (for example 12345-6789) */ private String zipCode; /** * Secondary constructor.
* Allows user to provide the value of the zipCode * * @param zipCode initial value of the zipCode */ public PostalCode(String zipCode) { setZipCode(zipCode); } /** * Mutator method.
* Sets the value of a zipCode to the given new value * * @param zipCode */ public void setZipCode(String zipCode) { this.zipCode = zipCode; } /** * method that converts the zipCode into the bar code format */ public StringBuilder computeBarCode() { // TODO Project 1 // IMPLEMENT THIS METHOD // 1. first remove all '-' for easy processing by calling replaceAll // 2. calculate the checksum by calling the private calculateChecksum method // 3. calculate the check digit by calling the private calculateCheckDigit method // 4. append the check digit to the zip string for final processing // 5. produce the bar code and save it in barCode variable // - check java API for description of StringBuilder append method StringBuilder barCode = new StringBuilder("|"); // use a for loop and a switch inside the loop return barCode; } /** * Business method that calculates the checksum for the given zipCode. * * @param zipCodeDigits the zipCode without '-' * @return checkSum */ private int calculateChecksum(String zipCodeDigits) { // TODO Project 1 int checkSum = 0; // IMPLEMENT THIS METHOD // HINT: to get the numeric value of each character // utilize Character.digit(zipCodeDigits.charAt(i),10) method inside // a for loop which runs over zipCodeDigits string return checkSum; } /** * Business method that calculates the check digit. * * @param checkSum sum of the digits in the zip code * @return check digit */ private int calculateCheckDigit(int checkSum) { // TODO Project 1 int checkDigit = 0; // IMPLEMENT THIS METHOD return checkDigit; } /** * Accessor method. * * @return the instance variable zipCode */ public String getZipCode() { return this.zipCode; } /** * toString method. * * @return the string representation of the PostalCode object */ public String toString() { return "The zip code: " + this.zipCode + " has the following bar code: " + computeBarCode(); } } PostalCodeClient.java /** * CLIENT CLASS Translate ZIP code into its bar code representation * * @author Anna Bieszczad * @version 10/14/2017 */ import java.util.*; public class PostalCodeClient { public static void main(String[] args) { final String VALID_AREA_CODE = "[0-9]{5}[-][0-9]{4}"; String zipInputStr; boolean valid; String answer; //get and validate user's input Scanner keyboard = new Scanner(System.in); do { do { System.out.println("Enter a ZIP code in the form DDDDD-DDDD"); zipInputStr = keyboard.nextLine(); valid = zipInputStr.matches(VALID_AREA_CODE); if (!valid) { System.out.println("Your input is invalid, please re-enter"); } } while (!valid); // create postalCode object PostalCode postalCode = new PostalCode(zipInputStr); // display the zipCode and its barCode System.out.println(postalCode); // check if the user wants to convert another zipCode System.out.println(); System.out.println("Would you like to generate another bar code?"); answer = keyboard.nextLine(); } while (answer.equalsIgnoreCase("yes")); System.out.println("Goodbye!"); } }Implement a solution to the problem described below. Your work must include the following: Your version of the PostalCode.java o include as many comments as are necessary to describe what the given code segment is doing o make sure that your code is formatted properly * Output of your program that shows multiple runs that test various scenarios * Please make sure to include your name in each file that you are submitting BEFORE STARTING PLEASE READ THE PROBLEM DESCRIPTION AND THE INSTRUCTIONS CAREFULLY For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the ZIP code. The zip code is encoded in half-height bars and full-height bars using encoding shown in the following table: Value Encoding 7 The barcode starts with a full-height bar followed by the encoded postal code digits, followed by a check digit, followed by full-height bar Each individual digit is represented by a set of five bars, two of which are full bars (as shown in the table above). The check digit is computed as follows: add up all digits, and choose the check digit to make the sum a multiple of 10. For example, the sum of the digits in the ZIP code 55555-1237 is 38, so the check digit is 2 to make the sum equal to 40 (multiple of 10). Together with the initial and terminal frame bars, 5555512372 barcode would be represented as: ululll
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts




