Answer:
public class RectangleArea {
public static void main(String[] args) {
Rectangle myRectangle = new Rectangle(15.8, 7.9);
double calArea = myRectangle.calcArea(15.8, 7.9);
System.out.println("The area is "+ calArea);
}
}
class Rectangle{
private double length;
private double width;
//Defined Constructor
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public double calcArea(double len, double wi){
return len* wi;
}
}
Explanation:
- This is solved with Java programming language
- Start by creating both classes RectangleArea and and Rectangle
- SInce both classes are in the same file, only one can be public
- Class Rectangle contains the three members are decribed by the question
- private double length, private double width and the method calcArea(). It also has a sefl-declared constructor.
- In the class RectangleArea, an object of Rectangle is created and initialized.
- The method calcArea is called using the created object and the value is printed.