CSE1030Z Week 05 Homework Problems

Composition

Short Problems

1. If a class X is a composition of a Y, then each X object contains a Y object. One reason for using composition is so that the X object can use the Y object to do some work. An example of this is the Die class from the Week 1 lab; each Die object is a compositon of a java.util.Random object; a die uses its own random number generator to produce random rolls. In this example, there are no accessors or mutators for the random number generator, so defensive copying is not needed.

Implement the Die class (API is here) ignoring the constructor with signature Die(int, Random) (it is there for testing purposes).

 

2. Three-dimensional computer models of shapes are often represented as a collection of triangles. In addition to the three points of the triangles, it is common to store a normal vector associated with the triangle. The normal vector indicates the direction perpendicular to a surface; for a triangle, the normal vector is the normal vector of the plane containing the triangle. Usually, the unit normal vector is desired (the normal vector having magnitude equal to 1).

For a triangle have points a, b, and c, the normal vector N can be computed as the cross product N = (b - a) × (c - a). The unit normal vector n can then be computed as n = N / | N | where | N | is the magnitude of N.

Change the Triangle class from the lectures to include a unit normal vector. The normal vector should be computed inside a constructor and stored as a separate Point object.

Moderate Problems

1. Implement the type.lib.CreditCard class from CSE1020 (API is here). Be sure to use composition on the Date objects (otherwise clients can directly change the issue and expiry dates).

 

2. An old practice labtest.

 

3. Another old practice labtest.

 

Long/Creative Problems

1. 3D printing is rapidly becoming a common method of manufacturing customized solid parts. To produce a part using 3D printing, a computer model of the part is required. A common file format for storing the model is the STL (stereolithography, or standard tessellation language) file format. The STL file essentially contains a list of triangles where each triangle is has a normal vector and three points.

Do some research to learn the structure of an ASCII (text) STL file. Then create a class called StlReader that can read an STL file and make the list of triangles available to a client. Your class should provide a method that allows the client to set different file names so that different STL files can be read without having to create a new StlReader object. If a client uses an StlReader object to read in a file, asks for the list of triangles, and reads in a different file, then the client's list of triangles should not change when the second file is read.

As part of my research, I have used 3D printing to produce patient specific guides for surgical navigation. On the left is an image of a computer model of a patient guide for wrist surgery, and on the right is the 3D printed guide placed on a plastic bone (the radius bone of the forearm). Click here if you want to see an image of a 3D printed guide in surgery (warning: picture is of an actual surgery; do not click if you are squeamish).