CIT-239 Java Programming Two Circles Lab03b Due Date You must demonstrate the so
ID: 3809289 • Letter: C
Question
CIT-239 Java Programming Two Circles Lab03b Due Date You must demonstrate the solution to this lab exercise to the instructor by Sunday, February 5, 2017, in order to receive credit for this work. Lab Exercise This lab is adapted from Programming Exercise 3.29 on pages 115 6 of the Liang textbook. WARNING The most important detail to remember about any computer work you do during class is to DOUBLE CHECK that your work is saved on your flash drive. Another technique for saving your work is to e-mail the source file (filename java) to yourself before you leave the room. Programming Exercise Write a program that prompts the user to enter the center coordinates and radii of two circles, and determines whether the second circle is inside the first or overlaps with the first, as shown in the illustration. (Feel free to reuse some or all of the code in the CircleDemo.java sample program, ifyou wish.) HINT 1 Circle2 is inside circlel if the distance between the two centers is r1 -r2 You may recall from your math courses that the two vertical bar characters are used to represent the absolute value. That is, if r1-r2Explanation / Answer
CircleInsideOrOverLaps.java
import java.util.Scanner;
public class CircleInsideOrOverLaps {
public static void main(String[] args) {
//Declaring variables
int x1,x2,y1,y2;
int r1,r2;
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting the center of the first circle (x1,y1)
System.out.print("Please enter X1: ");
x1=sc.nextInt();
System.out.print("Please enter y1: ");
y1=sc.nextInt();
//Getting the radius of circle 1
System.out.print("Please enter Radius 1: ");
r1=sc.nextInt();
//getting the center of the second circle (x2,y2)
System.out.print("Please enter X2: ");
x2=sc.nextInt();
System.out.print("Please enter Y2: ");
y2=sc.nextInt();
//Getting the radius of circle 2
System.out.print("Please enter Radius 2: ");
r2=sc.nextInt();
//calling the method by passing the points as arguments
double distance =calcDistance(x1,y1,x2,y2);
if(distance<Math.abs(r1-r2))
{
System.out.println("Circle2 is inside Circle1");
}
if(distance<=(r1+r2))
{
System.out.println("Circle2 overlaps Circle 1");
}
}
//Calculating the distance between two points
private static double calcDistance(int x1, int y1, int x2, int y2) {
return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
}
}
__________________
Output:
Please enter X1: 37
Please enter y1: 43
Please enter Radius 1: 34
Please enter X2: 44
Please enter Y2: 28
Please enter Radius 2: 13
Circle2 is inside Circle1
Circle2 overlaps Circle 1
__________________
output#2:
Please enter X1: 116
Please enter y1: 43
Please enter Radius 1: 29
Please enter X2: 159
Please enter Y2: 31
Please enter Radius 2: 19
Circle2 overlaps Circle 1
___________Thank You