Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use Java Part #1: Use the Factory pattern to address the following challenge ( 5 points ) Your job is to make it easy to

use Java Part #1: Use the Factory pattern to address the following challenge ( 5 points ) Your job is to make it easy to obtain a Pet from a factory-like class Pet is an abstract class that has 2 attributes Name Sound You should create 3 concrete types of pets Parakeet (makes the sound "Tweet tweet") Dog (makes the sound "Woof woof") Lion (makes the sound "Roar roar") You should create a factory class that allows the caller to create pets by specifying Name Acres of land where pets will live The # of acres of land determines what kind of pet is assigned 1 acre or less: parakeet 4 acre of less: dog 9 acre or less: lion Smaller pets are always preferred over larger ones For example if the caller has 2 acres, then a new Dog should be returned Your solution should minimally include 6 classes: The abstract Pet and concrete classes (4 classes) Factory class (1 class) An additional Test class Should demonstrate getting pets for the following acre sizes: 0, 3, 7 For each pet retrieved, print out its sound (to the output) Part #2: Choose ONE of the below challenges and solve it with one of the patterns we learned (5 points ) Option #1: Use the Decorator pattern to implement a photo booth There should be an abstract Photo class Has an abstract cost() method that returns the cost of the photo There should be 2 types of photos Color: $1 Black and white: $2 Each photo has the following options: Frame: extra $2 Glossy: extra $1 Digitally corrected: extra $4 Write a test class that demonstrates the creation of two instances of photos (using the decorator pattern we covered in class): A color one that is framed and glossy A black and white one that is extra glossy (apply glossy twice) and has been digitally corrected The test class should also demonstrate printing out the true cost of each of the 2 photo configurations specified in the previous instruction Option #2: Use the Observer pattern to improve communication between a Mayor and its citizens A Mayor has a name can do two types of things Add new citizens to his/her mailing list Make announcements When making announcements, a mayor e-mails each of their citizens e-mails that contain: Mayor says Where and will vary A Citizen has a name Can receive e-mails When an e-mail is received, it should be printed out to the console as soon as it is received. Each message printed out should look like this: just heard: Where and will vary The test class should Have a mayor named Mary Have the following 4 citizens sign up on Mary's mailing list Joey, Jane, Jerry, Jackie Have Mary mail citizens a message: "Don't forget to vote!" Option #3: Use the Adapter pattern to make a List into a Set Develop a class called StringList , a class which has the following operations: add(String) -- returns TRUE if string was added, FALSE otherwise remove(String) -- returns TRUE string was found and removed, FALSE otherwise Use either ArrayList or LinkedList to make StringList work Develop an interface called StringSetInterface , which has two methods add(String) -- returns TRUE if string was added, FALSE otherwise remove(String) -- returns TRUE string was found and removed, FALSE otherwise Develop a class called StringSetListAdapter that implements StringSetInterface and uses the StringList class you developed earlier to make the add() and remove() functions work. Need to make sure that you do not allow duplicates Develop a Test class that Adds the following Strings to a StringList the, quick, brown, fox, fox Adds the following Strings to a StringSetListAdapter the, quick, brown, fox, fox NOTE: you're welcome to add toString() methods as needed to debug, but they are not required for submission of the assignmen

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions