Design an abstract class called shape This class contains a


\"Design an abstract class called shape. This class contains a single constructor that accepts a numeric value that is used to calculate various values, one of which is area. Include in the class abstract mutator method called findArea that can be defined to find the are of various shapes. Also provide a concrete accessor method to return the area.

Design 2 concrete classes Circle and Square that inherits the class Shape. Each of these classes finds the respective area; I.E. are of circle and area of square.

You are responsible for providing any relevant variables

You are not required to write a test class\"

Please help




Design an abstract class called Shape. This class contains a single constructor that accepts a single numeric value that is used to calculate various values, one of which is area. Include in this class an abstract mutator method called findArea that can be defined to find the area of various shapes. Also provide a concrete accessor method to return the area. Design two concrete classes, Circle and Square, that inherits the class shape. Each of these classes finds the respective area; ie. area of circle and area of Square. You are responsible for providing any relevant variable(s). NB: You are NOT required to write a test class.

Solution

Shape.java

package abstractdemo;

public abstract class Shape {
   private double findArea;

   /**
   * @return the findArea
   */
   public abstract double getFindArea(double diameter);

   /**
   * @param findArea the findArea to set
   */
   public void setFindArea(double findArea) {
       this.findArea = findArea;
   }

}

Circle.java

package abstractdemo;

public class Circle extends Shape{
   private static final double PI = Math.PI; // constant
   @Override
   public double getFindArea(double diameter) {
       double radius = diameter / 2.0;
return PI * radius * radius;
   }

  

}

Why constructor for abstract class there is no use for can you eleborate it ?

 \
 \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site