Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Abstraction | OOP
Java OOP

Challenge: AbstractionChallenge: Abstraction

Task

An abstract class called Shape has been created for you. It contains two abstract methods: calculateArea() and calculatePerimeter(). Your task is to implement two classes: Rectangle and Circle. You need to inherit these classes from the abstract class Shape and override its methods. Here's a brief guide:

  • For the Circle class, you will need fields such as radius, and for the Rectangle class, you will need fields like width and height. These fields and their constructors are already provided for you. Use these fields when overriding the methods.
  • If you don't have strong geometry knowledge, here's a quick reference with formulas you need to use:
    • Circle Area: Pi * radius * radius;
    • Circle Perimeter: 2 * PI * radius;
    • Rectangle Area: width * height;
    • Rectangle Perimeter: 2 * (width + height).

To use the value of π (PI), make use of the Math library. You can use Math.PI to access the value of π.

Link to the task: GitHub
  • Use the @Override annotation to override both methods from the abstract class Shape: calculateArea() and calculatePerimeter().
  • For the Circle, utilize the formulas I mentioned above. To access the value of π, use Math.PI.
  • Use the syntax return "formula to calculate";.
  • Click the Run Tests button to check the correctness of your solution.
  • Everything was clear?

    Section 2. Chapter 8
    course content

    Course Content

    Java OOP

    Challenge: AbstractionChallenge: Abstraction

    Task

    An abstract class called Shape has been created for you. It contains two abstract methods: calculateArea() and calculatePerimeter(). Your task is to implement two classes: Rectangle and Circle. You need to inherit these classes from the abstract class Shape and override its methods. Here's a brief guide:

    • For the Circle class, you will need fields such as radius, and for the Rectangle class, you will need fields like width and height. These fields and their constructors are already provided for you. Use these fields when overriding the methods.
    • If you don't have strong geometry knowledge, here's a quick reference with formulas you need to use:
      • Circle Area: Pi * radius * radius;
      • Circle Perimeter: 2 * PI * radius;
      • Rectangle Area: width * height;
      • Rectangle Perimeter: 2 * (width + height).

    To use the value of π (PI), make use of the Math library. You can use Math.PI to access the value of π.

    Link to the task: GitHub
  • Use the @Override annotation to override both methods from the abstract class Shape: calculateArea() and calculatePerimeter().
  • For the Circle, utilize the formulas I mentioned above. To access the value of π, use Math.PI.
  • Use the syntax return "formula to calculate";.
  • Click the Run Tests button to check the correctness of your solution.
  • Everything was clear?

    Section 2. Chapter 8
    some-alt