An interface named SidedObject has been added that contains a method called displaySides(). Modify displaySides() so that it displays the number of sides the object possesses. Modify the GeometricFigure2 subclasses to include the use of the interface to display the number of sides of the figure. The displaySides() method in the Square2 class should output This figure has four sides. It should output This figure has three sides in the Triangle2 class. Code I was given - public abstract class GeometricFigure2 {     protected int height;     protected int width;     protected String figure;     public  GeometricFigure2(int h, int w, String f)     {         // write your code here     }     public int getHeight()     {         // write your code here     }     public int getWidth()     {         // write your code here     }     public String getFigure()     {         // write your code here     }   public interface SidedObject {     public void displaySides(); }   public class Square2 extends GeometricFigure2 {     private double area;     public Square2(int w, int h, String f)     {         super(w, h, f);     }     public double figureArea(int w, int h)     {         area = (double)(w * h);         return area;     }     public void displaySides()     {         // write your code here     } }   public class Triangle2 extends GeometricFigure2 {     private double area;     public Triangle2(int w, int h, String f)     {         super(w, h, f);     }     public double figureArea(int w, int h)     {         area = (double)(w * h * 0.5);         return area;     }     public void displaySides()     {         // write your code here     } } public class UseGeometric2 {     public static void main(String[] args)     {         double area;         int height;         int width;         String figureType;         GeometricFigure2[] figure = new GeometricFigure2[4];         Square2 f0 =  new Square2(5, 5, "Square");         Triangle2 f1 = new Triangle2(5, 5, "Triangle");         Square2 f2 = new Square2(10, 10, "Square");         Triangle2 f3 = new Triangle2(10, 10, "Triangle");         figure[0] = f0;         figure[1] = f1;         figure[2] = f2;         figure[3] = f3;         for(int i = 0; i < figure.length; i++)         {             height=figure[i].getHeight();             width=figure[i].getWidth();             figureType=figure[i].getFigure();             area=figure[i].figureArea(height, width);             System.out.println("The " + figureType + " with height = " +                     height + " and with width = " + width + " has an area of " +                     area);             figure[i].displaySides();         }     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

This is the question -

An interface named SidedObject has been added that contains a method called displaySides(). Modify displaySides() so that it displays the number of sides the object possesses. Modify the GeometricFigure2 subclasses to include the use of the interface to display the number of sides of the figure.

The displaySides() method in the Square2 class should output This figure has four sides. It should output This figure has three sides in the Triangle2 class.

Code I was given -

public abstract class GeometricFigure2
{
    protected int height;
    protected int width;
    protected String figure;

    public  GeometricFigure2(int h, int w, String f)
    {
        // write your code here
    }

    public int getHeight()
    {
        // write your code here
    }

    public int getWidth()
    {
        // write your code here
    }

    public String getFigure()
    {
        // write your code here
    }
 
public interface SidedObject
{
    public void displaySides();
}
 
public class Square2 extends GeometricFigure2
{
    private double area;
    public Square2(int w, int h, String f)
    {
        super(w, h, f);
    }
    public double figureArea(int w, int h)
    {
        area = (double)(w * h);
        return area;
    }
    public void displaySides()
    {
        // write your code here
    }
}
 
public class Triangle2 extends GeometricFigure2
{
    private double area;
    public Triangle2(int w, int h, String f)
    {
        super(w, h, f);
    }
    public double figureArea(int w, int h)
    {
        area = (double)(w * h * 0.5);
        return area;
    }
    public void displaySides()
    {
        // write your code here
    }
}
public class UseGeometric2
{
    public static void main(String[] args)
    {
        double area;
        int height;
        int width;
        String figureType;
        GeometricFigure2[] figure = new GeometricFigure2[4];
        Square2 f0 =  new Square2(5, 5, "Square");
        Triangle2 f1 = new Triangle2(5, 5, "Triangle");
        Square2 f2 = new Square2(10, 10, "Square");
        Triangle2 f3 = new Triangle2(10, 10, "Triangle");

        figure[0] = f0;
        figure[1] = f1;
        figure[2] = f2;
        figure[3] = f3;

        for(int i = 0; i < figure.length; i++)
        {
            height=figure[i].getHeight();
            width=figure[i].getWidth();
            figureType=figure[i].getFigure();
            area=figure[i].figureArea(height, width);
            System.out.println("The " + figureType + " with height = " +
                    height + " and with width = " + width + " has an area of " +
                    area);
            figure[i].displaySides();
        }
    }
}


Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education