Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

We Got the Address! 21/100 Days of Code

  • March 26, 2019March 26, 2019
  • by Richard Clarke

My latest feature finds the address containing the zipcode entered by a user.

 

This allows for obtaining the street number, street name, and properly removing it from the list when finished.

The address should be at the beginning of the list, the end, or somewhere in the middle. Finding it is made simple by the fact that each address is separated by commas.

If the target address is at the beginning of the list, it should have a comma after the zipcode. Since the zipcode is eight characters long, the index of the first comma should be eight more than that of the zipcode.

If the target address is at the end of the list, it will appear right after the last comma in the list. The zipcode should also appear eight characters before the end of the list.

All other addresses are considered to be in the middle of the list. Once the first instance of the zipcode occurs, I can create a temporary list to obtain the address.

By taking a substring of the original list from the beginning to eight characters after the index of the zipcode, the address becomes the last address in the temporary list. From there, I can reuse the same code for locating an address at the end of the list.

I used a switch statement and put the case for middle addresses above the one for end addresses. The only thing the middle case does is create the new aforementioned list.

Once the new list is created, the program can easily obtain the address by falling down to the end case. Not only does the program obtain the middle address, it does so without changing the original list (coming soon).

-CF

Related

I Can Hardly Reach! 20/100 Days of Code
Off With the Head! 22/100 Days of Code
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode coding Java

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress