Question: Using Methods In this lab you will create and use methods in the Zip Code class. Deliverable A zipped NetBeans project with 2 classes app




Using Methods In this lab you will create and use methods in the Zip Code class. Deliverable A zipped NetBeans project with 2 classes app Zip Code Classes App Zip Code Attributes String five Digit; String plus4; - Creates a Zip Code object 21 using the no-parameter constructor. - Creates a Zip Code object z2 using the one-parameter constructor. - Creates a Zip Code object 23 using the two-parameter constructor. - Using the method display, display the data from each of the 3 objects - Using the method displayPrefix, display the data from the object 21 using the input parameter 1 display the data from the object 22 using the input parameter 2 display the data from the object 23 using the input parameter 2 Constructors No-parameter One-parameter Two-parameter Methods String toString() void display() void displayPrefix(int p) o Suggestion: Use Netbeans to copy your last lab (Lab 02) to a new project called Lab03. Close Lab02. Work on the new Lab03 project then. The Zip Code Class 1. Attributes String fiveDigit String plus4 2. Constructors o 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 - " o one constructor with one parameter one input parameter for five Digit use the default value from the no-parameter constructor to initialize plus4 o one constructor with all (two) parameters one input parameter for each attribute o 3. 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. the toString method will have a similar functionality as App had in the first lab. it returns all the data from each object as a String . if the second attribute, plus4, is blank, display only the first attribute fivedigit, for instance, 16801 . if the second attribute, plus4, is not blank, display only the first attribute fivedigit followed by a "-" and then the plus4 attribute, for instance, 16802-1503 o displayo 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 O The App class 1. create a ZipCode object called 21 using the no-parameter constructor 2. create a Zip Code object called z2 using the one-parameter constructor with the value fiveDigit 90210 3. create a ZipCode object called 23 using the two-parameter constructor with the values o fiveDigit 16802 o plus4 1503 4. display all the data from each object using the method display() 5. display the prefix of 21 (using input parameter value 1) using the method displayPrefix(int p) 6. display the area of 22 (using input parameter value 2) using the method displayPrefix(int p) 7. display the area of z3 (using input parameter value 2) using the method displayPrefix(int p) Output The output should be similar to 00000 90210 16802-1503 Prefix = 000 Area = 10 Area = 02
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
