Labs
In this set of labs we will continue to use the Drawable interface from the java1/Interfaces project.
- Create a new interface named
ThreeDPrintablethat extendsDrawable, and declares avoidmethodthreeDPrint. Create a class,ThreeDModel, that implementsThreeDPrintable. Just useprintlnstatements in your method implementations.
(Solution: ThreeDPrintable1.java, ThreeDModel1.java)
- Create a
ThreeDPrinterclass with a privateThreeDPrintable[]field. Make sure it gets initialized with a non-null array. Give the class a public method allowing a user to add aThreeDPrintableobject to the array. Define aprintAll3DObjectsmethod that 3-D prints each item in the array. Create aPrinterUserclass whosemaincreates aThreeDPrinter, adds some model objects to it, and prints them.
(Solution: ThreeDPrinter1.java, PrinterUser1.java)
- Modify the
ThreeDPrintableinterface, adding a new abstract methodgenerateWireframe. What happens when you save this change?
Solve this issue by making generateWireframe a default method, providing a method body with a println.
(Solution: ThreeDPrintable2.java, ThreeDModel2.java, ThreeDPrinter2.java, PrinterUser2.java)