uebungen/sources/src/main/java/pr2/exceptions/eigene_ausnahme/Fuse.java

56 lines
1.4 KiB
Java

package pr2.exceptions.eigene_ausnahme;
/**
* Eine Sicherung im Stromkreis.
*/
public class Fuse {
/**
* 16 Ampere-Sicherung.
*/
public static final int A16 = 16;
/**
* 25 Ampere-Sicherung.
*/
public static final int A25 = 25;
/**
* 32 Ampere-Sicherung.
*/
public static final int A32 = 32;
/**
* Strom, bei dem die Sicherung auslöst.
*/
private final int tripCurrent;
/**
* Legt eine neue Sicherung an.
*
* @param tripCurrent Strom, bei dem die Sicherung auslösen soll.
* @throws IllegalCurrentException Ausnahme bei einem
* ungültigen Spannungswert.
*/
public Fuse(int tripCurrent) throws IllegalCurrentException {
// TODO: IllegalCurrentException werfen, wenn der Strom ungültig ist
if (tripCurrent != A16 && tripCurrent != A25 && tripCurrent != A32) {
throw new IllegalCurrentException(tripCurrent);
}
this.tripCurrent = tripCurrent;
}
/**
* Die Sicherung benutzen.
*
* @param current Strom, der durch die Sicherung fließt.
* @throws FuseTrippedException wird geworfen, wenn der Srom zu groß wird.
*/
public void use(int current) throws FuseTrippedException {
// TODO: FuseTrippedException werfen, wenn der Strom zu groß ist
if (current > tripCurrent) {
throw new FuseTrippedException(tripCurrent, current);
}
}
}