Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 5: Create a Java program to compute if two circles overlap 1. In NetBeans create a new project called Labl.2 initially with no Main
Part 5: Create a Java program to compute if two circles overlap 1. In NetBeans create a new project called Labl.2 initially with no Main class. 2. In the Project window create a new Java packnge called lab1.2. This can be done by right clicking on Source Packages and going to New Java Package 3. In packge lab12 create a class called Circle. This canbe e by right clicking on the packge and going to New Java Class... 4. At the beginning of Circle.java add the line package lab12; 5. In Circle java create a class called Circle with data fields for storing the radius, center x position and center y position of a circle. These should be private data fields of type double. 6. In class Circle add and implement the following public methods // constructor for creating a circle vith radius r centered at (x,y) public Circle(double x, double y, double r) // get method for the center x coordinate public double getXO // get method for center y coordinate public double getY // get method for radius public double getRadiusO // Tests if tuo Circle objects overlap // Returns true if the invoking object overlaps with Circle other // othervise returns false public boolean overlapsWith(Circle other) To compute if two circles overlap, we can check if the distance between their centers is less than or equal to the sum of their radii. The square root of x can be computed using Math.sqrt(x) 7. Add another class to packnge lab12 called Labl.2 (in its own file). In here create a main method. 8. Tell Net Beans that Lab12 is the Main class by doing the following: a. Right click on the project (Labl2) and go to Properties. b. Click on Run. c. In the text box labeled Main Class." type labi-2. Lab1.2 (or Browse and find the class). Then click OK 9. In the main method of class Labi 2 prompt the user for a center x, center y, and radius of two different circles. Use this input to create two different Circle object. Next, use method overlapsWith to compute if these Circles objects overlap. Finally, display the result to the screen. 10. When you are done, upload project Labl 2 to the server (see Part 4) Sample run of Lab12 Circles are to be entered in the format xyr where (x,y) is the center and r is the radius. Enter 1st circle: 341 Enter 2nd circle: 532 The circles overlap
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