University stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. class Bok implements TilUtlaan {
  2. private String utlaaner;
  3. private String tittel;
  4. private String forfatter;
  5. Bok(String tittel, String forfatter) {
  6. this.tittel = tittel;
  7. this.forfatter = forfatter;
  8. }
  9. /**
  10. * Returnerer bokens forfatter
  11. *
  12. * @return forfatter forfatteren til boken.
  13. */
  14. public String hentForfatter() {
  15. return forfatter;
  16. }
  17. /**
  18. * Returnerer bokens tittel.
  19. *
  20. * @return tittel tittelen paa boken.
  21. */
  22. public String hentTittel() {
  23. return tittel;
  24. }
  25. public void laanUt(String utlaaner) throws Exception {
  26. if (this.utlaaner != null) {
  27. throw new Exception(
  28. "Boken "+tittel+" er allerede laant ut "+
  29. "til "+this.utlaaner+"!"
  30. );
  31. } else {
  32. this.utlaaner = utlaaner;
  33. }
  34. }
  35. public void leverTilbake() throws Exception {
  36. if (utlaaner != null) {
  37. utlaaner = null;
  38. } else {
  39. throw new Exception("Boken "+tittel+" er ikke laant ut!");
  40. }
  41. }
  42. public String hentUtlaaner() {
  43. return utlaaner;
  44. }
  45. }