By the end of this activity, a student should be able to:
- Implement a simple Java class that uses other classes
- Use classes to accomplish more complex tasks
This recitation requires a reimplementation of the Circle class. The class uses the Point class developed in lecture.
A circle is an object that can be described by its location and radius. Depending on the application, a circle may have other properties like color, line width, fill color, etc... For the purpose of this recitation, it is sufficient to describe our circle using the location and radius. As such, our Circle class must include two fields called location and radius. Unlike the last recitation exercise, we will use the Point class that was developed in class.
For this recitation, you will implement the following:
- The constructors
- The accessor method getLocation().
- The mutator method setLocation().
- The method contains(), which returns true if the point passed is in the circle.
- The method intersects(), which returns true if this circle intersects the circle passed.
The Recitation3 class contains a main method that is the entry point into the program. When you submit the code during development, Java will automatically invoke the main method. You will implement this method to do the following:
- Get an x and y coordinates from the user.
- Create an instance of a Circle at (x,y) with radius=16.0 called circle16;
- Create another instance of a Circle at (14,12) with radius=40.0 called circle40;
- If the two circles intersect, print Circles intersect!; otherwise print Circles do not intersect!.
Step 4 requires knowledge of if-then-else statement in Java. If we have not covered it in class by the time you work on this recitation, you can look it up. It is straight forward and conceptually the same as in Python.
For example:
Enter x:
23
Enter y:
13
Circles intersect!