Question

Composite design pattern

In this assignment, you will create a letter (or email) from several sub-components. The subcomponents are reside in a hierarchy as follows.

image.png

Given the main program in the attachment (and below), create the necessary interfaces and classes to implement the rest of the program with the Composite design pattern.


public class Main {

public static void main(String[] args) {

String paragraph1 = "Lorem ipsum dolor sit... (long strings are shortened)";

String paragraph2 = "Curabitur eu laoreet ... (long strings are shortened)";

String paragraph3 = "Mauris eu mauris moll... (long strings are shortened)";

Paragraph par1 = new Paragraph(paragraph1);

Paragraph par2 = new Paragraph(paragraph2);

Paragraph par3 = new Paragraph(paragraph3);

LetterBody letterBody = new LetterBody();

letterBody.addComponent(par1);

letterBody.addComponent(par2);

letterBody.addComponent(par3);

Letter letter = new Letter("Test Letter", "Name Surname", "Test User");

letter.addComponent(letterBody);

letter.print();

}

}

At the end, the output of the program should look like below when you run the print method of the Letter class. Each line on each paragraph are wrapped at 80th column. If you are writing it in Java you can use WordUtils from Apache.


image.png

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

Request Answer!

10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Composite design pattern
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...

    Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...

  • Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter...

    Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods. The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings). Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of...

  • Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty...

    Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should set the appropriate field. For setMobile: if the method is passed a valid mobile phone number, it should set the appropriate field; otherwise it should do nothing. A string is a valid mobile phone number if every character in it is a digit from 0 to 9. Hints: To convert a string so you can...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • ArraysAndFiles.java and PartiallyFilledArray.java. They are shells that do not do anything. You will be adding code...

    ArraysAndFiles.java and PartiallyFilledArray.java. They are shells that do not do anything. You will be adding code after the comments in the main method and using the javadoc documentation to implement the other methods. Task 1: Send array data to the screen In ArraysAndFiles.java, create a new method printOnScreen and compile it. In the main method of ArraysAndFiles.java, add the code to declare and initialize the array of Strings and call printOnScreen to print the array on the screen. Task 2:...

  • Q1: Write a class that throws an ExtraneousStringException when a string has more than 30 characters...

    Q1: Write a class that throws an ExtraneousStringException when a string has more than 30 characters in it (see ExtraneousStringException.java. This java file does not need to be modified). Copy paste the contents of ExtraneousStringException.java into a new .java file, uncomment the commented out code, and write your code inside the main method. In the driver class, keep reading strings from the user until the user enters “DONE.” You may read your input from a file, or use the console....

  • Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...

    Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common? That is, what is the letter intersection count for the pair of strings? Let's look at 'd' first. The first string has 2 d's (d's occurrence count is 2), while the second has just 1 d (capitalization doesn't count) - so the intersection for the strings for d is 1. What about g? There the occurrence counts are 2 and 0, so the intersection...

  • Help with StringAnalysis Write a WidgetViewer application. Create a class StringAnalysis. This class has an event...

    Help with StringAnalysis Write a WidgetViewer application. Create a class StringAnalysis. This class has an event handler inner that extends WidgetViewerActionEvent it has instance variables StringSet sSet JTextField inputStr JLabel numStr JLabel numChar In the constructor, create a WidgetViewer object create sSet create a local variable JLabel prompt initialized to "Enter a String" create inputStr with some number of columns create a local variable JButton pushMe initialized to "Push to include String" create numStr initialized to "Number of Strings: 0"...

  • Bet you can't figure this out Create a Recursive Method to test whether a partial string...

    Bet you can't figure this out Create a Recursive Method to test whether a partial string is a subset of a full string. If the partial string is a subset of the full string return true. Otherwise return false.Create a Recursive Method to test whether a partial string is a subset of a full string. If the partial string is a subset of the full string return true. Otherwise return false. Here is the Main and Recursive below: (Note only...

  • I’m giving you code for a Class called GenericArray, which is an array that takes a...

    I’m giving you code for a Class called GenericArray, which is an array that takes a generic object type. As usual this is a C# program, make a new console application, and for now you can stick all of this in one big file. And a program that will do some basic stuff with it Generic Array List What I want you to do today: Create methods for the GenericArray, Easy(ish): public void Append (T, value) { // this should...

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