Question: Now that the Shape class is abstract and the main method will run, let's make one additional change. Inside the Shape class you'll notice a
Now that the Shape class is abstract and the main method will run, let's make one additional change. Inside the Shape class you'll notice a method called getArea that currently doesn't work. While we would want all of our shapes to have an area, we can't know what the contents of that method should be until we know what type of shape we're working with. This makes it a good candidate for being an abstract method.
Make the getArea method abstract Then, override that method in both Rectangle and Circle.
Finally, return to the main method. Start by adding all of the shapes to a single ArrayList. Then, loop through that ArrayList and print the results of getArea for each shape.
Main.java Rectangle.java Circle.java timesmathrm Shape.java
public class Main
public static void mainString args
Rectangle r new Rectangle;
Rectangle r new Rectangle;
Shape r new Rectangle;
Circle c new Circle;
Shape c new Circle;
Circle c new Circle;
Main.java
private int height;
public Rectangleint height, int width
superwidth;
this.height height;
public int getHeight
return height;
public void setHeightint height this.height height;
Main.java times Rectangle.java times Circle.java times Shape.java times
public class Circle extends Shape
public Circleint width
superwidth;
Main.java Rectangle.java
public abstract class Shape
private int width;
public Shapeint width
this.width width;
public int getWidth
return width;
public void setWidthint width
this.width width;
public double getArea
System.out.printlnDoesnt work!";
retirn :
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
