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.

PflanzengruppenKonfigurator.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package garten.model;
  7. /**
  8. *
  9. * @author Jan
  10. */
  11. class PflanzengruppenKonfigurator
  12. {
  13. private int alter = 1;
  14. private int pflanzenTyp =1;
  15. private int startlaenge =1;
  16. private Beet beet;
  17. public PflanzengruppenKonfigurator()
  18. {
  19. }
  20. public Pflanzengruppe erstellen() throws IllegalArgumentException
  21. {
  22. konfigurationPruefen();
  23. Pflanzengruppe pflgruppe = new Pflanzengruppe(pflanzenTyp,alter,startlaenge,beet);
  24. return pflgruppe;
  25. }
  26. public PflanzengruppenKonfigurator alter(int alter)
  27. {
  28. this.alter = alter;
  29. return this;
  30. }
  31. public PflanzengruppenKonfigurator pflanzenTyp(int pflanzenTyp)
  32. {
  33. this.pflanzenTyp = pflanzenTyp;
  34. return this;
  35. }
  36. public PflanzengruppenKonfigurator startlaenge(int startlaenge)
  37. {
  38. this.startlaenge = startlaenge;
  39. return this;
  40. }
  41. public PflanzengruppenKonfigurator beet(Beet beet)
  42. {
  43. this.beet = beet;
  44. return this;
  45. }
  46. private void konfigurationPruefen() throws IllegalArgumentException
  47. {
  48. if((pflanzenTyp ==1 || pflanzenTyp ==2) && alter > 3|| pflanzenTyp ==3 && alter > 4)
  49. {
  50. throw new IllegalArgumentException("Ein geringeres Alter muss gewählt werden");
  51. }
  52. if(pflanzenTyp ==1 && (startlaenge < 30 || startlaenge >50))
  53. {
  54. throw new IllegalArgumentException("Größe muss zwischen 30-50 liegen");
  55. }
  56. if((pflanzenTyp ==2 || pflanzenTyp ==3) && (startlaenge <10 || startlaenge >20))
  57. {
  58. throw new IllegalArgumentException("Größe muss zwischen 10-20 liegen");
  59. }
  60. }
  61. }