favorite We need a little bit of your help to keep things running, click on this banner to learn more

PP2. Week 7: April 19 - 25

Java Abstract Shape

Implement abstract class Shape.

Implement classes Rectangle, Triangle that extend Shape.

Implement class Square that extends Rectangle.

abstract class Shape
  int a, b;
  Shape(int a, int b) // Constructor
  abstract int Perimeter(); // Perimeter
  abstract double Area(); // Area

class Rectangle extends Shape
  Rectangle(int a, int b) // Constructor
  public int Perimeter() // Perimeter of Rectangle
  public double Area() // Area of Rectangle

class Square extends Rectangle
  Square(int a) // Constructor

class Triangle extends Shape
  int c;
  Triangle (int a, int b, int c) // Constructor
  public int Perimeter() // Perimeter of Triangle
  public double Area() // Area of Triangle


Each line contains one of three types of figures in the next format:

  • Square a
  • Rectangle a b
  • Triangle a b c


For each figure print in a separate line its perimeter and area.

Time limit 1 second
Memory limit 128 MiB
Input example #1
Square 5
Rectangle 2 3
Triangle 3 4 5
Output example #1
20 25.0
10 6.0
12 6.0
Author Mykhailo Medvediev