28 lines
695 B
Java
28 lines
695 B
Java
|
package records;
|
||
|
|
||
|
|
||
|
public class Rechteck extends Exception{
|
||
|
|
||
|
record Rectangle(double laenge, double breite) {
|
||
|
public Rectangle {
|
||
|
if (laenge <= 0 || breite <= 0) {
|
||
|
throw new java.lang.IllegalArgumentException(
|
||
|
String.format("Keine 0 oder negative Werte erlaubt."));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
|
||
|
Rectangle r = new Rectangle(4.0, 3.0);
|
||
|
Rectangle r2 = new Rectangle(1.0, 2.0);
|
||
|
|
||
|
System.out.println("Fläche: " + r.laenge() * r.breite());
|
||
|
System.out.println("Fläche2: " + r2.laenge() * r2.breite());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|