123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- class Bok implements TilUtlaan {
- private String utlaaner;
- private String tittel;
- private String forfatter;
-
- Bok(String tittel, String forfatter) {
- this.tittel = tittel;
- this.forfatter = forfatter;
- }
-
- /**
- * Returnerer bokens forfatter
- *
- * @return forfatter forfatteren til boken.
- */
- public String hentForfatter() {
- return forfatter;
- }
-
- /**
- * Returnerer bokens tittel.
- *
- * @return tittel tittelen paa boken.
- */
- public String hentTittel() {
- return tittel;
- }
-
- public void laanUt(String utlaaner) throws Exception {
- if (this.utlaaner != null) {
- throw new Exception(
- "Boken "+tittel+" er allerede laant ut "+
- "til "+this.utlaaner+"!"
- );
- } else {
- this.utlaaner = utlaaner;
- }
- }
-
- public void leverTilbake() throws Exception {
- if (utlaaner != null) {
- utlaaner = null;
- } else {
- throw new Exception("Boken "+tittel+" er ikke laant ut!");
- }
- }
-
- public String hentUtlaaner() {
- return utlaaner;
- }
- }
|