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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started