Question

********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information...

********************Java Assigment*******************************

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. (doctor of optometry)

String getStreet();

String getSuiteNum();

String getCity();

String getState();

String getZipCode(); }

Step 1

Create an abstract AddrLabel class that implements the AddrLabelInterface. Implement the following methods 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

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

2. Design and implement a class named LabelGenerator that is constructed to contain an object of type AddrLabelInterface. The class should contain the following static method (in addition to any other supporting methods),

public static String[] getLabelLines(AddrLabelInterface addr)

that returns in the 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, display each label one by one in the array

*******************There are some the same king on chegg but they are not completly right**********************

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*****************************************AddrLabelInterface.java********************************/

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();
}

/*****************************************AddrLabel.java**********************************/

public abstract class AddrLabel implements AddrLabelInterface{

   @Override
   public String getAttnName() {
      
       return null;
   }

   @Override
   public String getTitle() {
      
       return null;
   }

   @Override
   public String getName() {
           return null;
   }

   @Override
   public String getNameSuffix() {
      
       return null;
   }

   @Override
   public String getProfessionalSuffix() {
      
       return null;
   }

  

   @Override
   public String getSuiteNum() {
      
       return null;
   }

  
}

/***********************************************FriendAddrLabel.java********************************************/

public class FriendAddrLabel extends AddrLabel {

   private String name;
   private String street;
   private String city;
   private String state;
   private String zipcode;
  
   /**
   *
   * @param name
   * @param street
   * @param city
   * @param state
   * @param zipcode
   */
   // Constructor to create a object of this class
   public FriendAddrLabel(String name, String street, String city, String state, String zipcode) {
       super();
       this.name = name;
       this.street = street;
       this.city = city;
       this.state = state;
       this.zipcode = zipcode;
   }

   public String getName() {
       return name;
   }

   @Override
   public String getStreet() {
      
       return street;
   }

   @Override
   public String getCity() {
      
       return city;
   }

   @Override
   public String getState() {
      
       return state;
   }

   @Override
   public String getZipCode() {
      
       return zipcode;
   }

   @Override
   public String toString() {
       return "*********FriendAddrLabel********** " + name + " " + street + " " + city + ", " + state
               + "," + zipcode;
   }
  
  

}

/************************************************CompanyAddrLabel.java*******************************/

public class CompanyAddrLabel extends AddrLabel {

   private String attnName;
   private String title;
   private String companyName;
   private String street;
   private String state;
   private String zipCode;
  
   // Constructor to create a object of this class
   public CompanyAddrLabel(String attnName, String title, String companyName, String street, String state,
           String zipCode) {
       super();
       this.attnName = attnName;
       this.title = title;
       this.companyName = companyName;
       this.street = street;
       this.state = state;
       this.zipCode = zipCode;
   }

   public String getAttnName() {
       return attnName;
   }

   public String getTitle() {
       return title;
   }

   public String getCompanyName() {
       return companyName;
   }

   public void setState(String state) {
       this.state = state;
   }

   @Override
   public String getStreet() {
      
       return street;
   }

   @Override
   public String getCity() {
      
       return null;
   }

   @Override
   public String getState() {
       return state;
   }

   @Override
   public String getZipCode() {
       return zipCode;
   }

   @Override
   public String toString() {
       return "**********CompanyAddrLabel ****** "+"ATTN: " + attnName + " " + title + " " + companyName
               + " " + street + ", " + state + ", " + zipCode;
   }

  
}

/*****************************************************ProfessionalAddrLabel.java*****************************************/

public class ProfessionalAddrLabel extends AddrLabel {

  
   private String name;
   private String professionalSuffix;
   private String street;
   private String suite;
   private String city;
   private String state;
   private String zipcode;
  
   // Constructor to create a object of this class
   public ProfessionalAddrLabel(String name, String professionalSuffix, String street, String suite, String city,
           String state, String zipcode) {
       super();
       this.name = name;
       this.professionalSuffix = professionalSuffix;
       this.street = street;
       this.suite = suite;
       this.city = city;
       this.state = state;
       this.zipcode = zipcode;
   }

   public String getName() {
       return name;
   }

   public String getProfessionalSuffix() {
       return professionalSuffix;
   }

   public String getSuite() {
       return suite;
   }

   public String getZipcode() {
       return zipcode;
   }

   @Override
   public String getStreet() {
       return street;
   }

   @Override
   public String getCity() {
       return city;
   }

   @Override
   public String getState() {
       return state;
   }

   @Override
   public String getZipCode() {
       return zipcode;
   }

   @Override
   public String toString() {
       return "**********ProfessionalAddrLabel********* " + name + ", " + professionalSuffix + " "
               + street + ", " + suite + " " + city + ", " + state + ", " + zipcode ;
   }

  
}

/**********************************************LabelGenerator.java***********************************/

public class LabelGenerator {

   public static String[] getLabelLines(AddrLabelInterface addr) {
      
       String addLines[] = {addr.getAttnName()};
      
       return addLines;
      
      
   }
  
   public static void main(String[] args) {
      
       //AddLabelInterface type array that hold information about different type of object
       AddrLabelInterface add[] = new AddrLabelInterface[5];
       add[0] = new FriendAddrLabel("Jeff Taylor", "143 Main St.", "Towson", "MD", "21250");
       add[1] = new CompanyAddrLabel("Rebecca Rollins", "A1 Technology", "92 Autumn Drive", "Keene", "NH", "03431");
       add[2] = new ProfessionalAddrLabel("Sarah K. Phillips", "O.D.", "100 Oak Street   ", "Suite 904", "Omaha", "NE", "68007");
      
       for(int i=0;i<3;i++) {
          
       System.out.println(add[i].toString());
  
       }
       }
}
/***************************output******************************************/

Thanks a lot, Please let me know if you have any problem....

Add a comment
Know the answer?
Add Answer to:
********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal a...

    (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...

  • Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design...

    Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...

  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT