Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

: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

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_2

Step: 3

blur-text-image_3

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Explain how to compute net realizable value.

Answered: 1 week ago

Question

Explain basic descriptive analytic techniques used in auditing.

Answered: 1 week ago

Question

=+ 5. Below are some data from the land of milk and honey.

Answered: 1 week ago