• Post Reply Bookmark Topic Watch Topic
  • New Topic

Zip code project  RSS feed

 
Ebenezer Y Teah
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I begin this project?
[3-1] (Zip.java) Implement a class Zip that represents the USPS ZIP code. A Zip object should be able to represent either the original 5-digit ZIP format, as well as the newer and optional ZIP+4 format (which includes a hyphen and 4 additional digits). Examples are 54747 and 55105-1048.

Provide a Zip(String s) constructor with s initializing your two private fields String zipCode and boolean isPlus4, with the latter indicating if the format of zipCode is of the newer variety. Also provide a default constructor (no arguments) which sets the zipCode to 00000 and isPlus4 to false. Your first constructor should also validate the format of parameter s.  That is, if s is a valid original format zip code, set isPlus4 to false; otherwise, if it's a valid new ZIP+4 format, set isPlus4 to true. If it isn't either of these valid formats, then set the zipCode to 00000 and isPlus4 to false.

Also provide public instance methods getZipCode() to return the stored zip code, whatever its format; getZipPrefix() to return only the first five digits of the stored code if isPlus4==true or just the zip code otherwise; and a toString() method which returns the entire zipCode. Finally, provide your own version of public boolean equals(Object code), which returns true for Zip instances a and b, when they represent the same ZIP, no matter if they differ in formats or not: a.equals(b).

Then provide a main() method for Zip.  This should create three new Zip objects: one with the older 5-digit format, one with the newer 5+4 format but with the same prefix as the first, and one which is initialized with an invalid String (and which will get the value of 00000 as a result).  Invoke each of your instance methods against each of your three instances, and print out the results - except for equals().  Use it to test the equality of the first two zip codes, printing out the result.  Then test equals() for each valid Zip against the 00000 Zip, again printing out the result.

[3-2] (Gene.java) Write a program that reads a String from the user representing a DNA molecule as a sequence of letters A, C, G, and T, each letter representing a different base. Then determine whether it represents a potential gene, based on the following criteria:

• It begins with the start codon ATG.
• Its length is a multiple of 3.
• It ends with one of the stop codons TAG, TAA, or TGA. Index of(
• It has no intervening stop codons, anywhere in the sequence between the first three and last three codons.

The starting code for this problem has a main() method that reads the input String using StdIn.readLine(), and also provides a method isValidDNA(String str), which returns true if all characters in str are one of  A, C, G, and T. Otherwise return false.

Finish this main() implementation. you should validate the input String and print Not valid DNA if it contains any characters other than one of A, C, G, and T. Otherwise check it and print Is potential gene if it satisfies the previous criteria, and Is NOT potential gene otherwise.

 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "How do I start?" what exactly do you mean? Are you not sure how to set up a project in your IDE? Have you tried writing some code? What have you written so far? Please be more specific as to what you're confused about.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest: divide and rule. You have two projects, each comprising multiple parts. Start by reading a ZIP code from the command line and printing it out.
Once you can do that work out how to call a validate method. I suggest that method shou‍ld return a boolean. There are all sorts of ways you can validate a ZIP code. But, despite the amount of detail you have been provided with, there is something missing, which I suggest you ask. Can a ZIP code start 0? Can it end with −0xxx? One way of validation is to use a regular expression. There is a nice tutorial about that in the Java™ Tutorials. That might work, or you might think of a better way to do it. If you use a regular expression, remember that − is a metacharacter.

Do those things first and then get on to the other parts of the assignment.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!