Labs

In this set of labs we will continue to use the Drawable interface from the java1/Interfaces project.

  1. Create a new interface named ThreeDPrintable that extends Drawable, and declares a void method threeDPrint. Create a class, ThreeDModel, that implements ThreeDPrintable. Just use println statements in your method implementations.

(Solution: ThreeDPrintable1.java, ThreeDModel1.java)

  1. Create a ThreeDPrinter class with a private ThreeDPrintable[] field. Make sure it gets initialized with a non-null array. Give the class a public method allowing a user to add a ThreeDPrintable object to the array. Define a printAll3DObjects method that 3-D prints each item in the array. Create a PrinterUser class whose main creates a ThreeDPrinter, adds some model objects to it, and prints them.

(Solution: ThreeDPrinter1.java, PrinterUser1.java)

  1. Modify the ThreeDPrintable interface, adding a new abstract method generateWireframe. 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)


Prev -- Up