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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started