Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  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 librarymanager;
  7.  
  8. import librarymanager.Exception.InvalidSurnameException;
  9. import librarymanager.Exception.InvalidShortBioException;
  10. import librarymanager.Exception.InvalidSexException;
  11. import librarymanager.Exception.InvalidBeathDataException;
  12. import librarymanager.Exception.InvalidCountryException;
  13. import librarymanager.Exception.InvalidBirthDataException;
  14. import librarymanager.Exception.InvalidNameException;
  15. import librarymanager.Exception.InvalidAuthorIdException;
  16.  
  17.  
  18. /**
  19. *
  20. * @author admin
  21. */
  22. public class LibraryManager
  23. {
  24. public class Author
  25. {
  26. private String name;
  27. private String surname;
  28. private char sex;
  29. private String birthData;
  30. private String beathData;
  31. private String shortBio;
  32. private String country;
  33. private int authorID;
  34.  
  35. public Author( String name, String surname, char sex, String birtDate,String beathData, String shortBio, String country ,int newAuthorID)
  36. throws InvalidNameException, InvalidSurnameException, InvalidSexException, InvalidBirthDataException, InvalidBeathDataException, InvalidShortBioException, InvalidCountryException, InvalidAuthorIdException
  37. {
  38. this.setName(name);
  39. this.setSurname(surname);
  40. this.setSex(sex);
  41.  
  42. this.setBirthData(birthData);
  43. this.setBeathData(beathData);
  44.  
  45. this.setShortBio(shortBio);
  46. this.setCountry(country);
  47.  
  48. this.setAuthorID(newAuthorID);
  49.  
  50. }
  51.  
  52.  
  53. public int getAuthorID ()
  54. {
  55. return this.authorID;
  56. }
  57.  
  58.  
  59. public String getName()
  60. {
  61. return name;
  62. }
  63.  
  64.  
  65. public String getSurname()
  66. {
  67. return surname;
  68. }
  69.  
  70.  
  71. public char getSex()
  72. {
  73. return sex;
  74. }
  75.  
  76.  
  77. public String getBirthData()
  78. {
  79. return beathData;
  80. }
  81.  
  82. public String getShortBio()
  83. {
  84. return shortBio;
  85. }
  86.  
  87. public String getCountry()
  88. {
  89. return country;
  90. }
  91.  
  92.  
  93. public void setName(String newName) throws InvalidNameException
  94. {
  95. if (newName.length() > 1)
  96. {
  97. this.name = newName;
  98. }
  99. else
  100. {
  101. InvalidNameException e = new InvalidNameException("Invalid Name");
  102. throw e;
  103. }
  104. }
  105.  
  106. public void setSurname(String newSurname) throws InvalidSurnameException
  107. {
  108. if(newSurname.length() > 2)
  109. {
  110. this.surname = newSurname;
  111. }
  112. else
  113. {
  114. InvalidSurnameException e = new InvalidSurnameException("Invalid Surname");
  115. throw e;
  116. }
  117. }
  118. public void setSex(char newSex) throws InvalidSexException
  119. {
  120. if(newSex == 'm' || newSex == 'f')
  121. {
  122. this.sex = newSex;
  123. }
  124. else
  125. {
  126. InvalidSexException e = new InvalidSexException("Invalid Sex");
  127. throw e;
  128. }
  129. }
  130.  
  131.  
  132.  
  133. public void setBirthData(String newBirthData) throws InvalidBirthDataException
  134. {
  135. if(newBirthData.length() > 100)
  136. {
  137. this.birthData = newBirthData;
  138. }
  139. else
  140. {
  141. InvalidBirthDataException e = new InvalidBirthDataException("Invalid BirthData");
  142. throw e;
  143. }
  144. }
  145.  
  146. public void setBeathData(String newBeathData) throws InvalidBeathDataException
  147. {
  148. if(newBeathData.length() > 100)
  149. {
  150. this.beathData = newBeathData;
  151. }
  152. else
  153. {
  154. InvalidBeathDataException e = new InvalidBeathDataException("Invalid BeathData");
  155. throw e;
  156. }
  157. }
  158.  
  159. public void setShortBio(String newShortBio) throws InvalidShortBioException
  160. {
  161. if(newShortBio.length() > 2 && newShortBio.length() <= 10000)
  162. {
  163. this.shortBio = newShortBio;
  164. }
  165. else
  166. {
  167. InvalidShortBioException e = new InvalidShortBioException ("ShortBio length must be > 2 and < 10000");
  168. throw e;
  169. }
  170. }
  171.  
  172. public void setCountry(String newCountry) throws InvalidCountryException
  173. {
  174. if(newCountry.length() > 3)
  175. {
  176. this.country = newCountry;
  177. }
  178. else
  179. {
  180. InvalidCountryException e = new InvalidCountryException("Country is too short");
  181. throw e;
  182. }
  183. }
  184.  
  185. public void setAuthorID( int newAuthorID) throws InvalidAuthorIdException
  186. {
  187. if(newAuthorID.length() > 0 )
  188. {
  189. this.authorID = newAuthorID;
  190. }
  191. else
  192. {
  193. InvalidAuthorIdException e = new InvalidAuthorIdException("Invalid AuthorId");
  194. throw e;
  195. }
  196. }
  197. }
  198.  
  199.  
  200.  
  201.  
  202. /**
  203. * @param args the command line arguments
  204. */
  205. public static void main(String[] args)
  206. {
  207.  
  208. // TODO code application logic here
  209. }
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement