Question: COde in Java. Use the following class hierarchy for this question All WritingUtensil objects have the following attributes. A String variable indicating the brand of
COde in Java. Use the following class hierarchy for this question

All WritingUtensil objects have the following attributes.
A String variable indicating the brand of the WritingUtensil
A String variable representing the type of WritingUtensil (pen or pencil)
The WritingUtensil class also contains a toString method
The following table shows the intended behavior of the WritingUtensil class.
| Statement | Result |
| WritingUtensil bic = new WritingUtensil(bic, pen); | A new WritingUtensil object is created |
| bic.toString(); | The String This is a bic pen is returned |
(a) Write the complete WritingUtensil class. Your implementation must meet all specifications and conform to the behavior shown in the table.
Write the WritingUtensil class here:
The Pencil class is a subclass of WritingUtensil. The Pencil class does not contain any attributes or methods other than those found in the WritingUtensil class.
The constructor to the Pencil class accepts one parameter for the brand of the pencil. The constructor passes this parameter along with the string literal "pencil" to the WritingUtensil class to construct the object.
The following table shows the intended behavior of the Pencil class.
| Statement | Result |
| Pencil ticonderoga = new Pencil(ticonderoga); | A new Pencil object is created |
| ticonderoga.toString(); | The String This is a ticonderoga pencil is returned |
(b) Write the complete Pencil class. Your implementation must meet all specifications and conform to the behavior shown in the table.
Write the Pencil class here:
The MechanicalPencil class is a subclass of Pencil. The MechanicalPencil class contains one additional attribute not found in Pencil: a double variable representing the thickness of the pencils lead, in millimeters.
The constructor to the MechanicalPencil class accepts two parameters for the brand and lead thickness. The constructor passes the brand parameter to the Pencil class to construct the object.
The following table shows the intended behavior of the MechanicalPencil class.
| Statement | Result |
| MechanicalPencil pentel = new MechanicalPencil(pentel, 0.7); | A new MechanicalPencil object is created |
| pentel.toString(); | The String This is a pentel pencil with 0.7mm lead is returned |
(c) Write the complete MechanicalPencil class. Your implementation must meet all specifications and conform to the behavior shown in the table.
Write the MechanicalPencil class here:
WritingUtensil Pen Pencil Mechanical Pencil
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
