Me ajudem! Está correto?

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();
	}

}

:smiley:

Oi Thammy,

Qual o erro?

Fala brow,

Da algum erro?

Oi…

naum da erro mas naum sei se a logica tah correta…
tenho problemas com a utilizaçao de set e get…
a utilizaçao tah correta??

Nesse caso vc nao esta usando get e set, vc ta passando seus valores pelo Construtor, daí sua validação feita nos getters e setters, foi para o espaço.

Errado. A validação está a ser feita sim.

Errado. A validação está a ser feita sim.[/quote]

kkkk, agora q eu vi ela chamando get e set no construtor. Nao tinha visto, foi mal.

fiquei confusa…

tah certo ou errado??

[quote=ThammyOscarino]fiquei confusa…

tah certo ou errado??[/quote]

Ta certo sim.

Voce poderia usar um construtor sem parametros tb, e usar seus getters e setters, para atribuir e retornar valor.

ah naum…

entendii :smiley: :smiley:

Vlw gentee