Question: I need help writing the program called CirclePrecomputedArea in java please! They all inherit each other and call to each other. i also included what
I need help writing the program called CirclePrecomputedArea in java please! They all inherit each other and call to each other. i also included what the output of running the superclass should look like! There are different programs all together. There is CircleMain, CircleDynamicArea, Circle, and CirclePrecomputedArea.
Overall, you need to download and edit three files, namely:
Circle.java
CircleDynamicArea.java
CirclePrecomputedArea.java
You will need to write code in each of these files in order to make CircleMain.java compile and produce the correct output. As an example, under the commandline arguments this should produce the
following output:
Initial dynamic area:
Initial precomputed area:
Reset dynamic area:
Reset precomputed area:
TODO write your code below this comment. TODO write your code below this comment.
You need to do the following:
Define a class named CircleDynamicArea.
This class inherits from Circle.
Define a constructor which takes a double
to initialize the superclass with.
You'll need to use super.
Define a getArea instance method, which
returns the area of the circle calculated
from the current radius of the circle.
This can be determined from this expression:
Math.PI getRadius getRadius
TODO write your code below this comment.
You need to do the following:
Define a class named CirclePrecomputedArea.
This class inherits from Circle.
Define an instance variable named area, which
holds a double.
Define a constructor which takes a double
to initialize the superclass with.
You'll need to use super. Additionally,
you'll need to set area to the area of this
circle, using the same expression as you
used in CircleDynamicArea
Define getArea to simply return the value
in the area instance variable just like
a normal getter
Override the setRadius method to recompute
the value of the area, after setting the
radius of the circle to the new value.
You'll need to call the superclass' setRadius
method with super.
DO NOT MODIFY ANYTHING IN THIS FILE!!
public class CircleMain
public static void checkRadiusOkdouble expectedRadius, Circle circle
double haveRadius circle.getRadius;
if haveRadius expectedRadius
System.out.printlnRadius mismatch! Expected:
expectedRadius but we have:
haveRadius;
public static void mainString args
double initialRadius Double.parseDoubleargs;
double resetRadius Double.parseDoubleargs;
Circle dyn new CircleDynamicAreainitialRadius;
Circle pre new CirclePrecomputedAreainitialRadius;
checkRadiusOkinitialRadius dyn;
checkRadiusOkinitialRadius pre;
double initialDynArea dyngetArea;
double initialPreArea pre.getArea;
System.out.printlnInitial dynamic area: initialDynArea;
System.out.printlnInitial precomputed area: initialPreArea;
if initialDynArea initialPreArea
System.out.printlnAreas don't match initially";
else
dynsetRadiusresetRadius;
pre.setRadiusresetRadius;
checkRadiusOkresetRadius dyn;
checkRadiusOkresetRadius pre;
double resetDynArea dyngetArea;
double resetPreArea pre.getArea;
System.out.printlnReset dynamic area: resetDynArea;
System.out.printlnReset precomputed area: resetPreArea;
if resetDynArea resetPreArea
System.out.printlnAreas don't match after resetting the radius";
You need to do the following:
Define an abstract class named Circle
Define an instance variable for Circle
named radius. This variable holds a double.
Define a constructor which takes a
double to initialize the radius instance
variable with
Define a getter for radius
Define a setter for radius
Define an ABSTRACT method named getArea.
Abstract methods are always instance methods.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
