Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code computes the radius of a circle. Using static methods from the Math class complete the method that computes the radius of a

The following code computes the radius of a circle. Using static methods from the Math class complete the method that computes the radius of a circle using the formula r2=(x-h)2 +(y-k)2 , given the (x,y) coordinates of one point on its circumference and the (h,k) coordinates of its center.

public class Circle { public static void main(String[] C) { double x1 =14.25; double y1 =13.68; double xCenter = 25.678; double yCenter = 10.32547; System.out.println("The first given points of your circle is ("+x1+", "+y1+")"); System.out.println("The center points of your circle is ("+xCenter+", "+yCenter+")"); double radius = radius(x1,y1,xCenter,yCenter); System.out.println("The radio of your circunferent is "+ radius); //Use a method to find the integer part of the radio. double radiusfloor = Math.floor(radius); System.out.println("The floor of the radius of your circunference is "+ radiusfloor); } public static double radius(double x,double y,double cx, double cy) { double radius = 0.0; // write the expression to compute radius using the static methods pow() and sqrt() provided by Math class. return radius; }

}

Here is the JUnit Test:

import static org.junit.Assert.*; import org.junit.Test; public class CircleTest { @Test public void testRadius() { double epsilon = 1e-10; assertEquals("Circle.radius returned incorrect result", 0.0,Circle.radius(5,5,5,5), epsilon); assertEquals("Circle.radius returned incorrect result", 5, Circle.radius(3,4,0,0), epsilon); assertEquals("Circle.radius returned incorrect result", 13.19669493661197, Circle.radius(5.0285,1.055,5.24,14.25), epsilon); assertEquals("Circle.radius returned incorrect result", 63.97655820689325, Circle.radius(0,47,58,20), epsilon); } }

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

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

Students also viewed these Databases questions