Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions