Question
Requirements : //Code in simple java language As per usual, be sure to leave some comments (in your code) on how certain complex / unique
Requirements:
//Code in simple java language
As per usual, be sure to leave some comments (in your code) on how certain complex / unique parts of your program work.
Be sure to follow the instructions outlined [below] for each class / function EXACTLY as described. This includes small things such as making sure your methods are defined with the right names, using the appropriate / necessary data type for your parameter(s) / return type, etc.
Your final solution should NOT have any print statements anywhere in either file. You can of course utilize print statements to test your code / numbers as your developing this program, just be sure to delete them once you're done.
Tips:
Be sure to complete "step 1" before moving on to "step 2"; as the class described in step 2 is dependent on the class made during step 1.
You may notice that the formulas for the "intersect()" functions share a common aspect, so I recommend creating a function to deal with that portion of the needed calculation. Maybe make it a static function in class 'Point' which works with two 'Point' parameters. Think about it.
If you're unsure about a particular aspect the I didn't go over or purposely left vague for you to figure out on your own, yet you can't, feel free to contact me with your questions.
Be sure to test your classes function-by-function as you're developing your program and NOT all at once at the end.
STEP 1: Create a class called 'Point' with the following specifications.
NOTE: Nothing within this class should be private. Also these should NOT be static.
Attributes:
A double variable called "X"
A double variable called "Y"
Constructors:
A default constructor which will initialize the 'X' and 'Y' fields with zero.
A "Point(double, double);" constructor that'll assign the parameters' values into the 'X' and 'Y' fields
{ 1st parameter => X & 2nd parameter => Y }
------------------------------------------------------------------------------------------------------------
STEP 2: Create a class called 'Circle' with the following specifications.
NOTE: Nothing within this class should be private. Also these should NOT be static.
Attributes:
A double variable called "radius"
A Point object called "center"
HINT: (refer back to lecture on Aggregation)
Constructors:
A default constructor which will initialize the 'radius' field with zero.
NOTE: Make sure that 'center' is initialized with a "(0, 0) point" here.
A "Circle(double);" constructor that'll assign the parameter's value into the 'radius' field.
REQUIREMENT: You MUST invoke the class' own mutator method to handle this assignment.
NOTE: Make sure that 'center' is initialized with a "(0, 0) point" here.
A "Circle(Point, double);" that'll assign the parameters into their respective fields.
REQUIREMENT: You MUST invoke the class' own mutator method to handle the assignment operation for 'radius'.
Methods:
A mutator function, for attribute 'radius', called "setRadius".
REQUIREMENT: Make sure that if the parameter's value is negative, then the assigned value should be zero instead.
A function, with NO parameters, called "getArea" which (as the name implies) will calculate and return what the area of our Circle is.
Formula: (PI * R ^ 2)
NOTE: You can simply use the value of 3.14159 for 'PI'.
A function, with NO parameters, called "getCircumference" which (as the name implies) will calculate and return what the perimeter of our Circle is.
Formula: (2 * PI * R)
NOTE: You can simply use the value of 3.14159 for 'PI'.
A function called "intersect" with a 'Point' parameter which will return true if the argument lies within the Circle's area (including the edge), otherwise it'll return false.
TIP: The easiest way to figure this out is to compare the lengths of the radius and the distance between the two Points. If you don't know how to calculate a square root, here's an alternate formula you can use:
(p2.Y p1.Y)2 + (p2.X p1.X)2 radius2
EXTRA CREDIT: An overloaded "intersect" function with a 'Circle' parameter which will return true if the argument intersects with this Circle object (including the edge), otherwise it'll return false.
TIP: The easiest way to figure this out is to compare the lengths of the sum of the radii and the distance between the two center Points. If you don't know how to calculate a square root, here's an alternate formula:
(p2.Y p1.Y)2 + (p2.X p1.X)2 (radius_A + radius_B)2
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