Question: :Java Design/Programming A toolbox contains various named tools that can be used in a way that depends on the specific tool. The tool interface is:

:Java Design/Programming

A toolbox contains various named tools that can be used in a way that depends on the specific tool. The tool interface is:

interface Tool extends Cloneable { String getName(); void use(); }

There are several classes of tools for our problem domain: Eraser, Pencil, Protractor, Ruler, Paper.

A toolbox can return (get()) to the client a copy of a stored tool object based on its name, or throw NoSuchElementException if no tool exists in the toolbox with the given name. The toolbox can be populated with new tools (the add() method).

The toolbox interface is:

interface Toolbox { void add(Tool tool);

Tool get(String toolName); }

a. Use the Prototype pattern to design the toolbox and tools. Write the UML class diagram.

b. Implement the design in Java. Write contracts for all methods. To keep things simple, the Tool.use() method should just println("Using " + name()).

c. Write a ToolTest class with a main() method that exemplifies how the toolbox is used: - create the toolbox - populate it with one tool of each kind - call get for several named tools and 'use' them

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!