Implements interface RegularPolygon to class Sqaure
Implements interface RegularPolygon to class Sqaure.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkgclass;
public class Rectangle { // i cant tell whats wrong with this
private double length;
private double width;
public Rectangle(double len, double w) {
length = len;
width = w;
}
public void setLength(double len) {
length = len;
}
public void setWidth(double w) {
width = w;
}
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
public double getArea() {
return length * width;
}
}
Solution Square.java
// i cant tell whats wrong with that code
class Square extends Rectangle {
// derived class
public Square(int len) {
super(len, len);
}
public static void main(String[] args) {
Rectangle r = new Square(100);
r.setLength(20);
System.out.println(r.getWidth());
}
}
public interface RegularPolygon { /** * * @return the perimeter of the regular polygon (n * length) */ double getPerimeter(); }
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images