Guest User

Untitled

a guest
Jul 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. package datatypes;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class Customer {
  7.  
  8. private String firstName;
  9. private String lastName;
  10. private long telePhone;
  11. private long cellPhone;
  12. private String email;
  13. private int skinType;
  14. private long id;
  15. List<Treatment> treatmentList;
  16.  
  17. public Customer(String first, String last, long tPhone, long cPhone, String mail, int type) {
  18. if (first == null) {
  19. throw new IllegalArgumentException("first cannot be null");
  20. }
  21. if (last == null) {
  22. throw new IllegalArgumentException("last cannot be null");
  23. }
  24. if (tPhone < 0L) {
  25. throw new IllegalArgumentException("tPhone must be >= 0, was: " + tPhone);
  26. }
  27. if (cPhone < 0L) {
  28. throw new IllegalArgumentException("cPhone must be >= 0, was: " + cPhone);
  29. }
  30. if (mail == null) {
  31. throw new IllegalArgumentException("mail cannot be null");
  32. }
  33. if ((type < 1) || (type > 4)) {
  34. throw new IllegalArgumentException("type must be 1-4, was: " + type);
  35. }
  36. if (first.trim().equals("")) {
  37. throw new IllegalArgumentException("first must have atleast one letter");
  38. }
  39. if (first.length() > 32) {
  40. throw new IllegalArgumentException("first must be at most 32 letters");
  41. }
  42. if (last.trim().equals("")) {
  43. throw new IllegalArgumentException("last must have atleast one letter");
  44. }
  45. if (last.length() > 32) {
  46. throw new IllegalArgumentException("last must be at most 32 letters");
  47. }
  48.  
  49. this.firstName = formatName(first);
  50. this.lastName = formatName(last);
  51. this.telePhone = tPhone;
  52. this.cellPhone = cPhone;
  53. this.email = mail;
  54. this.skinType = type;
  55. this.treatmentList = new ArrayList();
  56. }
  57.  
  58. private String formatName(String name) {
  59. if (name == null) {
  60. throw new IllegalArgumentException("name cannot be null");
  61. }
  62. if (!(isNameValid(name))) {
  63. throw new IllegalArgumentException("name is not valid");
  64. }
  65.  
  66. String result = "";
  67.  
  68. result = result + Character.toUpperCase(name.charAt(0));
  69. for (int i = 1; i < name.length(); ++i) {
  70. result = result + Character.toLowerCase(name.charAt(i));
  71. }
  72.  
  73. return result;
  74. }
  75.  
  76. public static boolean isNameValid(String name) {
  77. if (name == null) {
  78. throw new IllegalArgumentException("name cannot be null");
  79. }
  80. if (name.trim().equals("")) {
  81. return false;
  82. }
  83.  
  84. return ((name.length() >= 1) && (name.length() <= 32));
  85. }
  86.  
  87. public static boolean isSkinTypeValid(int type) {
  88. return ((type >= 1) && (type <= 4));
  89. }
  90.  
  91. public static boolean isSkinTypeValid(String type) {
  92. int t;
  93. try {
  94. t = Integer.parseInt(type);
  95. } catch (NumberFormatException ex) {
  96. return false;
  97. }
  98.  
  99. return isSkinTypeValid(t);
  100. }
  101.  
  102. public String getFirstName() {
  103. return this.firstName;
  104. }
  105.  
  106. public void setFirstName(String name) {
  107. if (name == null) {
  108. throw new IllegalArgumentException("name cannot be null");
  109. }
  110.  
  111. this.firstName = name;
  112. }
  113.  
  114. public String getLastName() {
  115. return this.lastName;
  116. }
  117.  
  118. public void setLastName(String name) {
  119. if (name == null) {
  120. throw new IllegalArgumentException("name cannot be null");
  121. }
  122.  
  123. this.lastName = name;
  124. }
  125.  
  126. public long getTelephone() {
  127. return this.telePhone;
  128. }
  129.  
  130. public void setTelephone(long phone) {
  131. this.telePhone = phone;
  132. }
  133.  
  134. public long getCellphone() {
  135. return this.cellPhone;
  136. }
  137.  
  138. public void setCellphone(long phone) {
  139. this.cellPhone = phone;
  140. }
  141.  
  142. public String getEmail() {
  143. return this.email;
  144. }
  145.  
  146. public void setEmail(String mail) {
  147. this.email = mail;
  148. }
  149.  
  150. public int getSkinType() {
  151. return this.skinType;
  152. }
  153.  
  154. public void setSkinType(int type) {
  155. this.skinType = type;
  156. }
  157.  
  158. public long getID() {
  159. return this.id;
  160. }
  161.  
  162. public void setID(long id) {
  163. this.id = id;
  164. }
  165.  
  166. public List<Treatment> getTreatmentList() {
  167. return this.treatmentList;
  168. }
  169.  
  170. public void setTreatmentList(List<Treatment> list) {
  171. if (list == null) {
  172. throw new IllegalArgumentException("list cannot be null");
  173. }
  174.  
  175. this.treatmentList = list;
  176. }
  177. }
Add Comment
Please, Sign In to add comment