Question: Java Program: Use the Factory pattern to address the following challenge... Your job is to make it easy to obtain a Pet from a factory-like

Java Program: Use the Factory pattern to address the following challenge...

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 or 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).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!