ADDRESSES AND ZIP CODES The BotswanaPost has decided to automate their mail sorting activity. They have decided to adopt the zip code method of sorting. A zip code is a 5 digit number (equivalent to a private bag/p.o. box number) that specifies the destination of a mail article (letter/ parcel). They have instituted that companies sending bulk mail must use a barcode denoting the zip code. The encoding scheme for a five five digit ZIP code are followed by a correction digit, which is computed as follows: Add up all digits, and choose the correction digit to make the sum a multiple of 10. For example, the ZIP code 95014 has sum of digits 19, so the correction digit is 1 to make the sum equal to 20. Each digit of the ZIP code, and the correction digit, is encoded according to the following table: 1: 0 0 0 1 1 2: 0 0 1 0 1 3: 0 0 1 1 0 4: 0 1 0 0 1 5: 0 1 0 1 0 6: 0 1 1 0 0 7: 1 0 0 0 1 8: 1 0 0 1 0 9: 1 0 1 0 0 0: 1 1 0 0 0 where 0 denotes a half bar and 1 a full bar. Note that they represent all combinations of two full and three half bars. Write a Java program that reads addresses from a file called address.dat and writes out the addresses to a file called zip.dat with the zip code replaced by the bar code. Use ! for full bars and : for half bars. For example 95014 becomes (950141): !:!:: :!:!: !!::: :::!! :!::! :::!!
Write the program so that it will substitute for any number of * on one line, and accepts any number of lines as input. Each input line should be used, for example, to create a StringTokenizer with appropriate delimiters. You ll find an array of useful methods from the String, the StringTokenizer, and the StringBuffer classes that could make this one a walkover! 3. ADDRESSES AND ZIP CODES Each line in the file is of the form: lastname firstname city zipCode . For example, Nkgau Tallman Molepolole 95014 For the above line, your program should write the output to the file as follows: Tallman Nkgau Molepolole !:!:: :!:!: !!::: :::!! :!::! :::!!
You MUST use the following program structure: Use a method to encode the zip code. It takes in a 5 digit number and returns a 6 digit number after adding the correction digit. Use a method to take in a 6 digit number representing a zip code followed by the correction digit and returns a string representing the bar code. You MUST use a Boolean method to verify that the 6 digit number indeed represents a zip code. You MUST also use a method that takes in a digit and returns a string representing the encoding of that digit as given in the above table.
Just some suggestions... Would be great if you actually sounded like you knew a few of the topics relating to your questions so that you could actually drop some specific questions.
Try Googling: "Java Array Tutorial" and "Java Methods Tutorial" crunch up some code that leads towards solving your problem then get back to the question. Hopefully once all this is learnt it will only be an algorithmic type question.