/*-// ComplexDyn.java: non-static members class-*/ public class ComplexDyn { public double re; /*++-// Nonstatic variables: entire class -++*/ public double im; public ComplexDyn() /*++-// Default constructor-++*/ { re = 0; im = 0; } public ComplexDyn(double x, double y) /*++-// Constructor-++*/ { re = x; im = y; } public void add(ComplexDyn other) /*++-// Dynamic other + this-++*/ { this.re = this.re + other.re; this.im = this.im + other.im; } public void mult(ComplexDyn other) /*++-// Dynamic other*this-++*/ { ComplexDyn ans = new ComplexDyn(); /*++-// Intermediate -++*/ ans.re = this.re * other.re - this.im * other.im; ans.im = this.re * other.im + this.im * other.re; this.re = ans.re; /*++-// Copy value into returned object-++*/ this.im = ans.im; } public static void main(String[] argv) /*-// Static Main: object indep-*/ { ComplexDyn a, b; /*++-//Declare 2 Complex objects -++*/ a = new ComplexDyn(); /*++-// Create the objects-++*/ b = new ComplexDyn(4.7, 3.2); ComplexDyn c = new ComplexDyn(3.1, 2.4); /*++-// Declare, create-++*/ System.out.println("a,b = ("+ a.re+","+a.im+"),("+b.re+","+b.im+"),"); System.out.println("c = ("+c.re+", "+c.im+")"); c.add(b); /*++-//Non-static addition-++*/ a = c; System.out.println("b+c = (" + a.re + ", " + a.im+"),"); c = new ComplexDyn(3.1, 2.4); c.mult(b); /*++-// Non-static multiplication-++*/ System.out.println("b*c = (" + c.re + ", " + c.im+")"); }}