Write class Circle - a two dimensional circle. Have set and get methods and a to
ID: 3632724 • Letter: W
Question
Write class Circle - a two dimensional
circle.
Have set and get methods and a toString( ) method.
Have an Area( ) method that calculates the
circle area.
Write class Sphere that extends class Circle.
Have a new Area( ) function that computes
the surface area of the sphere.
Have set and get methods and a toString( ) method.
Use an array of 10 Sphere objects.
Test your Sphere class in a loop that
sets the sphere radius from 1-10.
Use a separate loop that
prints out the sphere surface area
for each sphere in the array.
Explanation / Answer
//The circle class ############## ##circle.java## ############## public class circle { private final double pi = 3.14; private double radius; public circle() { this.radius = 0; } public circle(double rad) { this.radius = rad; } public void setRadius(double rad) { this.radius = rad; } public double getRadius() { return radius; } public double Area() { return pi*radius*radius; } @Override public String toString() { return "radius = " + radius; } } //The sphere class ############## ##sphere.java# ############## public class sphere extends circle{ public sphere(double rad) { super(); super.setRadius(rad); } public sphere() { super(); super.setRadius(0); } @Override public double Area() { return (4*super.Area())/3; } @Override public void setRadius(double rad) { super.setRadius(rad); } @Override public double getRadius() { return super.getRadius(); } @Override public String toString() { return "radius = " + super.getRadius(); } public static void main(String args[]) { sphere[] spArr= new sphere[10]; //constructing the sphere array for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.