CS 3340 OOP
Exercise 2: UML to Java
Chapter Readings: TIJ [6]

Goal: To learn how the Unified Modeling Language (UML) presents designs that are easily implemented in Java.


Tutorial

Read this tutorial on UML: ex2a.pdf

Consider this UML design for Complex Numbers: ex2b.pdf

and its equivalent Java implementation: ComplexNumber.java

Here is much more advanced, and convoluted, UML design: ex2c.pdf

and its corresponding Java implementation: Advanced.java

Here is a demo which runs ComplexNumber.java and Advanced.java: demo

Note: We are using UML to present the classes and methods, but not detailed UML to exactly specify the algorithms/method implementation (see CS 4311: UML Colloboration Diagrams). For this reason, accept the method implementations in Advanced.java as a "given", and not flowing from the UML. The demo OUTPUT does suggest the logic of the calls. In the exercise below, a "word" description is provided - along with the OUTPUT - to specify the implementation.


Assignment

See the assignment UML: ex2d.pdf

Convert the UML to Ex2.java, only the class Ex2 needs to be public - the other classes can be in the same file.

Be sure to "instrument" every constructor and method, for example, in class G, method x():

System.out.println("G.x()");

so this shows exactly what is called.

After making the classes and outlining the methods, here is what each class should do (besides some of the obvious/logical things):

public class Ex2: main() should construct G and call x().

class E: default constructor should call the other constructor (Advanced.java shows how to do this). Besides backing up i, setI() should call z().

class F: x() should getJ() and call q().

Be sure to pay attention to italics, and what that means.

Neither E or F actually construct anything, they get instances via other methods.

interface H: doesn't do anything, it's an interface.

Where does y() actually get implemented?

class G: G() should construct I, and setI(). getJ() should get J from i. x() should call super class x(), and also local y().

class I: I() should construct J. z() should call q().

class J: just printlns.

If you've done it correctly, the output should look like:

Ex2.main()
E.E(s): s=Here is a string from default constructor
E.E()
F.F()
G.G()
I.I()
J.J()
E.setI(i)
I.z()
J.q()
G.x()
F.x()
G.getJ()
I.getJ()
J.q()
G.y()

Turn-In: Ex2.java, including commented-out listing of resultant output.