1. The following interface and classes have to do with the storage of informatio
ID: 3747035 • Letter: 1
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 of the described classes below.
public interface AddrLabelInterface {
String getAttnName();
String getTitle(); // Mr., Mrs., etc. String getName();
String getNameSuffix(); // e.g., Jr., III String getProfessionalSuffix(); // O.D. String getStreet();
String getSuiteNum();
String getCity();
String getState();
String getZipCode();
}
Step 1
(doctor of optometry)
Create an abstract AddrLabel class that implements only the following methods of the AddrLabelInterface to return an empty string: getAttnName(), getTitle(), getNameSuffix(), getProfessionalSuffix(), and getSuiteNum(). The rest of the methods should be left unimplemented (i.e., as abstract methods).
Step 2
Create a class named FriendAddrLabel declared as a (concrete) subclass of the abstract AddrLabel class. The FriendAddrLabel class should be designed to store only the Name, Street, City, State and ZipCode fields.
e.g.,
Jeff Taylor
143 Main St. Towson, MD 21250
Step 3
Create a class named CompanyAddrLabel declared as a (concrete) subclass of the abstract AddrLabel class. The CompanyAddrLabel class should be designed to store only the AttnName, Title, CompanyName, Street, City, State and ZipCode fields.
e.g.,
ATTN: Rebecca Rollins A1 Technology
92 Autumn Drive Keene, NH 03431
1
Step 4
Create a class named ProfessionalAddrLabel declared as a (concrete) subclass of the abstract AddrLabel class. The ProfessionalAddrLabel class should be designed to store only the Name, ProfessionalSuffix, Street, Suite, City, State and ZipCode fields.
e.g.,
Sarah K. Phillips, O.D.
100 Oak Street, Suite 904 Omaha, NE 68007
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 in the array of strings the address lines as they should be printed for the given address label type.
Create a simple main program that creates a number of address object types, and stores in an array of elements of type AddrLabelInteface. Using a simple for loop (i.e., enhanced for loop), display each label one by one in the array.
Explanation / Answer
using ConsoleApp.Address;
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
LabelGenerator generator = new LabelGenerator();
generator.Label = new FriendAddrLabel();
foreach(string line in generator.getLabelLines())
{
Console.Write(line);
}
Console.WriteLine();
generator.Label = new CompanyAddrLabel();
foreach (string line in generator.getLabelLines())
{
Console.Write(line);
}
Console.WriteLine();
generator.Label = new ProfessionalAddrLabel();
foreach (string line in generator.getLabelLines())
{
Console.Write(line);
}
Console.WriteLine();
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApp.Address
{
public class LabelGenerator
{
public AddrLabelInterface Label { get; set; }
public String[] getLabelLines()
{
return new string[] { Label.getAttnName(),
" ",
Label.getTitle(),
" ",
Label.getName(),
" ",
Label.getNameSuffix(),
" ",
Label.getProfessionalSuffix(),
" ",
Label.getStreet(),
" ",
Label.getSuiteNum(),
" ",
Label.getCity(),
" ",
Label.getState(),
" ",
Label.getZipCode()};
}
}
}
namespace ConsoleApp.Address
{
public class ProfessionalAddrLabel : AddrLabel
{
public new string getNameSuffix()
{
return "Sarah K. Phillips";
}
public new string getProfessionalSuffix()
{
return "O.D.";
}
public new string getSuiteNum()
{
return "Suite 904";
}
public override string getCity()
{
return "Omaha";
}
public override string getState()
{
return "NE";
}
public override string getStreet()
{
return "100 Oak Street";
}
public override string getZipCode()
{
return "68007";
}
public override string getName()
{
return "";
}
}
}
namespace ConsoleApp.Address
{
public class CompanyAddrLabel : AddrLabel
{
public new string getAttnName()
{
return "ATTN:";
}
public new string getProfessionalSuffix()
{
return "A1 Technology";
}
public new string getTitle()
{
return "";
}
public override string getCity()
{
return "Keene";
}
public override string getState()
{
return "NH";
}
public override string getStreet()
{
return "92 Autumn Drive";
}
public override string getZipCode()
{
return "03431";
}
public override string getName()
{
return "Rebecca Rollins";
}
}
}
namespace ConsoleApp.Address
{
public class FriendAddrLabel : AddrLabel
{
public override string getName()
{
return "Jeff Taylor";
}
public override string getZipCode()
{
return "21250";
}
public override string getStreet()
{
return "143 Main St.";
}
public override string getState()
{
return "MD";
}
public override string getCity()
{
return "Towson";
}
}
}
namespace ConsoleApp.Address
{
public abstract class AddrLabel : AddrLabelInterface
{
public string getAttnName()
{
return "";
}
public string getNameSuffix()
{
return "";
}
public string getProfessionalSuffix()
{
return "";
}
public string getSuiteNum()
{
return "";
}
public string getTitle()
{
return "";
}
public abstract string getZipCode();
public abstract string getStreet();
public abstract string getState();
public abstract string getCity();
public abstract string getName();
}
}
namespace ConsoleApp.Address
{
public interface AddrLabelInterface
{
string getAttnName();
string getTitle(); // Mr., Mrs., etc.
string getName();
string getNameSuffix(); // e.g., Jr., III
string getProfessionalSuffix(); // O.D.
string getStreet();
string getSuiteNum();
string getCity();
string getState();
string getZipCode();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.