Question
1. The following interface and classes have to do with the storage of information that may appear on a mailing label. Design and implement each
1. The following interface and classes have to do with the storage of information that may appear on a mailing label. Design and implement each of the described classes below.
The items in bold are items that are a required part of every address. All other items are optional.
public interface AddrLabelInterface {
String getAttnName();
String getTitle(); // Mr., Mrs., etc.
String getName();
String getNameSuffix(); // e.g., Jr., III
String getProfessionalSuffix(); // O.D. (doctor of optometry)
String getStreet();
String getSuiteNum();
String getCity();
String getState();
String getZipCode();
}
Step 1 Create an AddrLabel class that implements the AddrLabelInterface, and that has an instance variable for each of the items of an address in bold above. (Thus, the class should have a constructor that is passed a value for each of these.) Implement each method in bold to return the corresponding stored value. Implement the remaining methods (e.g., getAttnName()) to just return an empty string.
Step 2 Create a class named FriendAddrLabel declared as a subclass of the AddrLabel class. There is no implementation needed for this class other than a constructor, since FriendAddrLabel objects only contain the information required of all AddrLabel objects (i.e., name, street, city, state and zip). This constructor should pass along these values to the AddrLabel class via a call to its constructor.
Step 3 Create a class named CompanyAddrLabel declared as a subclass of the abstract AddrLabel class. The CompanyAddrLabel class should be designed to store only the AttnName, and override the getAttnName method inherited from the AddrLabel class.
e.g., ATTN: Rebecca Rollins A1 Technology 92 Autumn Drive Keene, NH 03431 2
Step 4 Create a class named ProfessionalAddrLabel declared as a subclass of the abstract AddrLabel class. The ProfessionalAddrLabel class should be designed to store only the ProfessionalSuffix and SuiteNum values, and override the getProfessionalSuffix and getSuiteNum methods inherited from the AddrLabel class.
e.g., Sarah K. Phillips, O.D. 100 Oak Street, Suite 904 Omaha, NE 68007
2. Design and implement a class named LabelGenerator that is constructed to contain an object of type AddrLabelInterface. The class should contain the following method (in addition to any other supporting methods), public String[] getLabelLines() that returns as an array of strings the address lines as they should be printed for the given address label type.
3. Create a simple main program that creates a number of address object types, and stores in an array of type AddrLabelInteface. Using a simple for loop (enhanced for loop), display each label one by one in the array by call to method getLabelLines for each. The polymorphism is in the various ways that each AddrLabel label behaves.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started