In: Computer Science
URGENT!!!
DO THIS PROGRAM IN JAVA
Write a complete Java console based program following these steps:
1. Write an abstract Java class called Shape which has only one abstract method named getArea();
2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape.
3. Write the driver code tat tests the classes and methods you write above.
//Shape.java public abstract class Shape { abstract double getArea(); }
////////////////////////////////////////////////////////
//Rectangle.java public class Rectangle extends Shape{ private int width; private int height; public Rectangle(int width, int height) { this.width = width; this.height = height; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } double getArea() { return width*height; } public String toString() { return "Rectangle{" + "width=" + width + ", height=" + height + '}'; } }
////////////////////////////////////////////////////////
//Main.java public class Main { public static void main(String[] args) { Rectangle rectangle = new Rectangle(3,4); System.out.println("Area = "+rectangle.getArea()); } }
Area = 12.0