Special offer for new customers: 5% OFF your first order! Use coupon: GWRITERSclose

Java

The ZipCode Class
Attributes
String fiveDigit
String plus4
Constructors
one constructor with no input parameters
since it doesn’t receive any input values, you need to use the default values below:
fiveDigit – “00000”
plus4 – “0000”
one constructor with one parameter
one input parameter for fiveDigit
use the default value from the no-parameter constructor to initialize plus4
one constructor with all (two) parameters
one input parameter for each attribute
Methods (same as last lab)
public String toString()
returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
toString() is a special method, you will learn more about it in the next lessons
it needs to be public
it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
display()
this method gets the “toString()” value (whatever is returned by toString() ) and uses “System.out.println” to display it.
you need to decide what is the type of this method
displayPrefix(int p)
this method receives an input parameter, an int number p
based on p’s value
if p’s value is 1
uses “System.out.println” to display the zipcode’s prefix, i.e., its 3 first digits.
if the fiveDigit is “10022”, displays “100”
if p’s value is2
uses “System.out.println” to display the zipcode’s area, i.e., its fourth and fifth digits.
if the fiveDigit is “10022”, displays “22”
for any other value of p, it should not display anything
The App class
create a ZipCode object called z1 using the no-parameter constructor
create a ZipCode object called z2 using the one-parameter constructor with the value
fiveDigit  90210
create a ZipCode object called z3 using the two-parameter constructor with the values
fiveDigit  16802
plus4  1503
display all the data from each object using the method display()
display the prefix of z1 (using input parameter value 1) using the method displayPrefix(int p)
display the area of z2 (using input parameter value 2) using the method displayPrefix(int p)

You can leave a response, or trackback from your own site.
Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes