Answered step by step
Verified Expert Solution
Question
1 Approved Answer
------------------------------------------------------------------------------------------------------------------------ The tester is provide : SemiCircleTester.java public class SemiCircleTester { public static void main(String[] args) { SemiCircle semi1 = new SemiCircle(100, 100, 60); //test
------------------------------------------------------------------------------------------------------------------------
The tester is provide :
SemiCircleTester.java
public class SemiCircleTester { public static void main(String[] args) { SemiCircle semi1 = new SemiCircle(100, 100, 60); //test contains //the center is not contained in the circle System.out.println(); System.out.println("center contained: " + semi1.contains(100, 100)); System.out.println("Expected: false"); //the E W N points not contained System.out.println("E contained: " + semi1.contains(160, 100)); System.out.println("Expected: false"); System.out.println("W contained: " + semi1.contains(40, 100)); System.out.println("Expected: false"); System.out.println("N contained: " + semi1.contains(100, 40)); System.out.println("Expected: false"); //point in semi-circle System.out.println(semi1.contains(120, 75)); System.out.println("Expected: true"); //point in whole circle but not in semi circle System.out.println(semi1.contains(110, 120)); System.out.println("Expected: false"); SemiCircle black = new SemiCircle(50, 150, 40); SemiCircle red = new SemiCircle(100, 170, 40); SemiCircle green = new SemiCircle(90, 140, 40); SemiCircle blue = new SemiCircle(115, 165, 15); System.out.println("black & green intersect: " + black.intersects(green)); System.out.println("Expected: true"); System.out.println("green & black intersect: " + green.intersects(black)); System.out.println("Expected: true"); System.out.println("black & red intersect : " +black.intersects(red)); System.out.println("Expected: true"); System.out.println("red & black intersect : " +red.intersects(black)); System.out.println("Expected: true"); System.out.println("red & green intersect: " + red.intersects(green)); System.out.println("Expected: true"); System.out.println("green & red intersect: " + green.intersects(red)); System.out.println("Expected: true"); System.out.println("red & blue intersect : " + red.intersects(blue)); System.out.println("Expected: false"); System.out.println("blue & red intersect : " + blue.intersects(red)); System.out.println("Expected: false"); System.out.println("black & blue intersect : " + black.intersects(blue)); System.out.println("Expected: false"); System.out.println("blue & black intersect : " + blue.intersects(black)); System.out.println("Expected: false"); } }Write a class SemiCircle in Java that represents the northern half of a circle in 2D space. A SemiCircle has center coordinates and a radius. Define a constructor: public SemiCircle(int centerX, int centerY, int theRadius) Implement the following methods public boolean contains(int otherX, int otherY) returns true if the point given by the coordinates is inside the SemiCircle. Otherwise it returns false. Note: the point will be contained in the SemiCircle if the distance from the center to the print is less than the radius and the point is above the diameter. A point on the circumference or diameter is not contained in the SemiCircle public boolean intersects( SemiCircle other) returns true if the two SemiCircles intersect; otherwise it returns false. Two semicircles "intersect" if at least one, but not all three of the western, northern, and eastern extreme points of one semicircle are contained in the other. This means they do not intersect if one is completely contained in the other or if the extreme point only touches the other semicircle Look at the drawing below. The western, northern, and eastern extreme points of the top semicircle are labeled W, N, and E respectively In the lower drawing: The three larger semicircles all intersect The W point of the green one is inside the black one green and black intersect The N point of the red one is inside the green one ->green and red intersect. The E point of the black one is inside the red one => black and red intersect. The small blue semicircle does not intersect with any of the large ones. The blue semicircle and the black one have no points in common => they do not intersect The blue one and the green one have no points in common => they do not intersect The blue one is completely contained in the red one > they do not intersect SemiCircles
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