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 }\times\mathrm{ Shape.java
1 public class Main {
public static void main(String[] args){
| Rectangle r1= new Rectangle(10,5);
Rectangle r2= new Rectangle(10,5);
Shape r3= new Rectangle(10,5);
Circle c1= new Circle(15);
Shape c2= new Circle(15);
Circle c3= new Circle(15);
}
}
14
```
```
Main.java
}
```
private int height;
public Rectangle(int height, int width)\{
super(width);
this.height = height;
\}
public int getHeight()\{
return height;
\}
public void setHeight(int height)\{ this.height = height;
Main.java \(\times \) Rectangle.java \(\times \) Circle.java \(\times \) Shape.java \(\times \)
```
public class Circle extends Shape {
public Circle(int width){
super(width);
}
```
```
Main.java Rectangle.java
public abstract class Shape {
private int width;
public Shape(int width){
this.width = width;
}
public int getWidth(){
return width;
}
public void setWidth(int width){
this.width = width;
}
public double getArea(){
System.out.println("Doesn't work!");
retirn :
```
Now that the Shape class is abstract and the main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!