import java.util.Scanner;
abstract class Forma {
public void imprime() {
System.
out.
println("Área: " + area
()); System.
out.
println("Perímetro: " + perimetro
()); }
public abstract double area();
public abstract double perimetro();
}
class Retangulo extends Forma {
private double comprimento;
private double largura;
Retangulo
(double comprimento,
double largura
) throws Exception { if (comprimento <= 0 || largura <= 0) {
throw new Exception("ONDE JÁ SE VIU LARGURA E/OU COMPRIMENTO NEGATIVO?"); }
this.comprimento = comprimento;
this.largura = largura;
}
@Override
public double area() {
return comprimento * largura;
}
@Override
public double perimetro() {
return 2 * (largura + comprimento);
}
public double getComprimento() {
return comprimento;
}
public double getLargura() {
return largura;
}
public void setComprimento
(double comprimento
) throws Exception { if (comprimento < 0) {
throw new Exception("ONDE JÁ SE VIU COMPRIMENTO NEGATIVO?"); }
this.comprimento = comprimento;
}
public void setLargura
(double largura
) throws Exception { if (largura < 0) {
throw new Exception("ONDE JÁ SE VIU LARGURA NEGATIVA?"); }
this.comprimento = largura;
}
}
class Programa {
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in); double comprimento = sc.nextDouble();
double largura = sc.nextDouble();
try {
Retangulo retangulo = new Retangulo(comprimento, largura);
retangulo.imprime();
retangulo.setComprimento(-comprimento);
System.
out.
println(ex.
getMessage()); }
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKYWJzdHJhY3QgY2xhc3MgRm9ybWEgewogICAgcHVibGljIHZvaWQgaW1wcmltZSgpIHsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIsOBcmVhOiAiICsgYXJlYSgpKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlBlcsOtbWV0cm86ICIgKyBwZXJpbWV0cm8oKSk7CiAgICB9CiAgICBwdWJsaWMgYWJzdHJhY3QgZG91YmxlIGFyZWEoKTsKICAgIHB1YmxpYyBhYnN0cmFjdCBkb3VibGUgcGVyaW1ldHJvKCk7Cgp9CgpjbGFzcyBSZXRhbmd1bG8gZXh0ZW5kcyBGb3JtYSB7CiAgICBwcml2YXRlIGRvdWJsZSBjb21wcmltZW50bzsKICAgIHByaXZhdGUgZG91YmxlIGxhcmd1cmE7CgogICAgUmV0YW5ndWxvKGRvdWJsZSBjb21wcmltZW50bywgZG91YmxlIGxhcmd1cmEpIHRocm93cyBFeGNlcHRpb24gewogICAgICAgIGlmIChjb21wcmltZW50byA8PSAwIHx8IGxhcmd1cmEgPD0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXhjZXB0aW9uKCJPTkRFIErDgSBTRSBWSVUgTEFSR1VSQSBFL09VIENPTVBSSU1FTlRPIE5FR0FUSVZPPyIpOwogICAgICAgIH0KICAgICAgICB0aGlzLmNvbXByaW1lbnRvID0gY29tcHJpbWVudG87CiAgICAgICAgdGhpcy5sYXJndXJhID0gbGFyZ3VyYTsKICAgIH0KCiAgICBAT3ZlcnJpZGUKICAgIHB1YmxpYyBkb3VibGUgYXJlYSgpIHsKICAgICAgICByZXR1cm4gY29tcHJpbWVudG8gKiBsYXJndXJhOwogICAgfQogICAgQE92ZXJyaWRlCiAgICBwdWJsaWMgZG91YmxlIHBlcmltZXRybygpIHsKICAgICAgICByZXR1cm4gMiAqIChsYXJndXJhICsgY29tcHJpbWVudG8pOwogICAgfQogICAgcHVibGljIGRvdWJsZSBnZXRDb21wcmltZW50bygpIHsKICAgICAgICByZXR1cm4gY29tcHJpbWVudG87CiAgICB9CiAgICBwdWJsaWMgZG91YmxlIGdldExhcmd1cmEoKSB7CiAgICAgICAgcmV0dXJuIGxhcmd1cmE7CiAgICB9CiAgICBwdWJsaWMgdm9pZCBzZXRDb21wcmltZW50byhkb3VibGUgY29tcHJpbWVudG8pIHRocm93cyBFeGNlcHRpb24gewogICAgICAgIGlmIChjb21wcmltZW50byA8IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEV4Y2VwdGlvbigiT05ERSBKw4EgU0UgVklVIENPTVBSSU1FTlRPIE5FR0FUSVZPPyIpOwogICAgICAgIH0KICAgICAgICB0aGlzLmNvbXByaW1lbnRvID0gY29tcHJpbWVudG87CiAgICB9CiAgICBwdWJsaWMgdm9pZCBzZXRMYXJndXJhKGRvdWJsZSBsYXJndXJhKSB0aHJvd3MgRXhjZXB0aW9uIHsKICAgICAgICBpZiAobGFyZ3VyYSA8IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEV4Y2VwdGlvbigiT05ERSBKw4EgU0UgVklVIExBUkdVUkEgTkVHQVRJVkE/Iik7CiAgICAgICAgfQogICAgICAgIHRoaXMuY29tcHJpbWVudG8gPSBsYXJndXJhOwogICAgfQp9CgpjbGFzcyBQcm9ncmFtYSB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgZG91YmxlIGNvbXByaW1lbnRvID0gc2MubmV4dERvdWJsZSgpOwogICAgICAgIGRvdWJsZSBsYXJndXJhID0gc2MubmV4dERvdWJsZSgpOwogICAgICAgIHRyeSB7CiAgICAgICAgICAgIFJldGFuZ3VsbyByZXRhbmd1bG8gPSBuZXcgUmV0YW5ndWxvKGNvbXByaW1lbnRvLCBsYXJndXJhKTsKICAgICAgICAgICAgcmV0YW5ndWxvLmltcHJpbWUoKTsKICAgICAgICAgICAgcmV0YW5ndWxvLnNldENvbXByaW1lbnRvKC1jb21wcmltZW50byk7CiAgICAgICAgfSBjYXRjaCAoRXhjZXB0aW9uIGV4KSB7CiAgIAkgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihleC5nZXRNZXNzYWdlKCkpOwogICAgICAgIH0KICAgIH0KfQ==