Question: The OldCircle interface defines a circle by 3 numbers a, b, c where a, b, c are the coefficients of the equation (x a) 2

The OldCircle interface defines a circle by 3 numbers a, b, c where a, b, c are the coefficients of the equation (x a)2 + (y b)2 = c.

Note : The center of the circle is at point (a,b) and radius of the circle is equal to the square root of c.

The code for OldCircle interface is as follow:-

public interface OldCircle {

public double [] getCoeff( );

}

The NewCircle interface defines a circle by its radius and center, which is represented by a java.awt.Point object.

The code for NewCircle interface is as follow:-

public interface NewCircle {

public double getRadius( );

public Point getCenter( );

}

We have some legacy code which implements OldCircle.

public class OldCircleImpl implements OldCircle {

private double [] coeff = new double[3];

public OldCircleImpl(double a, double b, double c) {

coeff[0] = a; coeff[1] = b; coeff[2] = c;

}

public double [ ] getCoeff( ) {

return coeff;

}

}

However, the class PrintCircle below only uses the NewCircle interface.

public class PrintCircle {

public static void printCircle(NewCircle newCircle) {

System.out.println(" r = " + newCircle.getRadius( ));

System.out.println("center = [" + newCircle.getCenter( ).getX()

+ " , " + newCircle.getCenter( ).getY() + "]");

}

}

Part A

Implement an object adapter CircleObjectAdapter class that allows the PrintCircle class to print the details of a OldCircleImpl object. Write a simple test program that creates an OldCircleImpl object with a = 10.0, b = 15.0, c = 25.5 and prints the details of the circle using the PrintCircle class. Draw a class diagram to show your solution.

Part B

Implement a class adapter CircleClassAdapter class that allows the PrintCircle class to print the details of an OldCircleImpl object. Write a simple test program that creates a CircleClassAdapter object with a = 10.0, b = 15.0, c = 25.5 and prints the details of the circle using the PrintCircle class. Draw a class diagram to show your solution.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!