Alguem poderia conferir pra ver se tah tudo ok no meu código??
Vlww
package ex4;
public class Rectangle {
private double lenght;
private double width;
public Rectangle (double l, double w){
setLenght(l);
setWidth(w);
}
public double getLenght() {
return lenght;
}
public void setLenght(double lenght) {
if (lenght >= 0.0 && lenght <= 20.0)
this.lenght = lenght;
else
this.lenght = 0.0;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
if (width >= 0.0 && width <= 20.0)
this.width = width;
else
this.width = 0.0;
}
public void calculaArea(){
double area = lenght * width;
System.out.println("A area é: " + area);
}
public void calculaPerimetro (){
double perimetro = (2 * lenght) + (2 * width);
System.out.println("O perimetro é: " + perimetro);
}
}
package ex4;
import java.util.Scanner;
public class RectangleTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Informe altura do retangulo:");
double lenght = input.nextDouble();
System.out.println("Informe largura do retangulo:");
double width = input.nextDouble();
Rectangle rectangle1 = new Rectangle(lenght, width);
rectangle1.calculaArea();
rectangle1.calculaPerimetro();
}
}