The Artima Developer Community
Sponsored Link

Java Answers Forum
Arrays & Methods

1 reply on 1 page. Most recent reply: Nov 1, 2005 10:41 PM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Becky Gatang'i

Posts: 2
Nickname: bex
Registered: Nov, 2005

Arrays & Methods Posted: Nov 1, 2005 10:26 AM
Reply to this message Reply
Advertisement
Please help me solve this question:

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.


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Arrays & Methods Posted: Nov 1, 2005 10:41 PM
Reply to this message Reply
Warring Mstwana:

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.

Flat View: This topic has 1 reply on 1 page
Topic: im thining to add video to my site something like that maybe www.cast-tv.co Previous Topic   Next Topic Topic: JOptionPane and Exception question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use