Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package datatypes;
- import java.util.ArrayList;
- import java.util.List;
- public class Customer {
- private String firstName;
- private String lastName;
- private long telePhone;
- private long cellPhone;
- private String email;
- private int skinType;
- private long id;
- List<Treatment> treatmentList;
- public Customer(String first, String last, long tPhone, long cPhone, String mail, int type) {
- if (first == null) {
- throw new IllegalArgumentException("first cannot be null");
- }
- if (last == null) {
- throw new IllegalArgumentException("last cannot be null");
- }
- if (tPhone < 0L) {
- throw new IllegalArgumentException("tPhone must be >= 0, was: " + tPhone);
- }
- if (cPhone < 0L) {
- throw new IllegalArgumentException("cPhone must be >= 0, was: " + cPhone);
- }
- if (mail == null) {
- throw new IllegalArgumentException("mail cannot be null");
- }
- if ((type < 1) || (type > 4)) {
- throw new IllegalArgumentException("type must be 1-4, was: " + type);
- }
- if (first.trim().equals("")) {
- throw new IllegalArgumentException("first must have atleast one letter");
- }
- if (first.length() > 32) {
- throw new IllegalArgumentException("first must be at most 32 letters");
- }
- if (last.trim().equals("")) {
- throw new IllegalArgumentException("last must have atleast one letter");
- }
- if (last.length() > 32) {
- throw new IllegalArgumentException("last must be at most 32 letters");
- }
- this.firstName = formatName(first);
- this.lastName = formatName(last);
- this.telePhone = tPhone;
- this.cellPhone = cPhone;
- this.email = mail;
- this.skinType = type;
- this.treatmentList = new ArrayList();
- }
- private String formatName(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name cannot be null");
- }
- if (!(isNameValid(name))) {
- throw new IllegalArgumentException("name is not valid");
- }
- String result = "";
- result = result + Character.toUpperCase(name.charAt(0));
- for (int i = 1; i < name.length(); ++i) {
- result = result + Character.toLowerCase(name.charAt(i));
- }
- return result;
- }
- public static boolean isNameValid(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name cannot be null");
- }
- if (name.trim().equals("")) {
- return false;
- }
- return ((name.length() >= 1) && (name.length() <= 32));
- }
- public static boolean isSkinTypeValid(int type) {
- return ((type >= 1) && (type <= 4));
- }
- public static boolean isSkinTypeValid(String type) {
- int t;
- try {
- t = Integer.parseInt(type);
- } catch (NumberFormatException ex) {
- return false;
- }
- return isSkinTypeValid(t);
- }
- public String getFirstName() {
- return this.firstName;
- }
- public void setFirstName(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name cannot be null");
- }
- this.firstName = name;
- }
- public String getLastName() {
- return this.lastName;
- }
- public void setLastName(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name cannot be null");
- }
- this.lastName = name;
- }
- public long getTelephone() {
- return this.telePhone;
- }
- public void setTelephone(long phone) {
- this.telePhone = phone;
- }
- public long getCellphone() {
- return this.cellPhone;
- }
- public void setCellphone(long phone) {
- this.cellPhone = phone;
- }
- public String getEmail() {
- return this.email;
- }
- public void setEmail(String mail) {
- this.email = mail;
- }
- public int getSkinType() {
- return this.skinType;
- }
- public void setSkinType(int type) {
- this.skinType = type;
- }
- public long getID() {
- return this.id;
- }
- public void setID(long id) {
- this.id = id;
- }
- public List<Treatment> getTreatmentList() {
- return this.treatmentList;
- }
- public void setTreatmentList(List<Treatment> list) {
- if (list == null) {
- throw new IllegalArgumentException("list cannot be null");
- }
- this.treatmentList = list;
- }
- }
Add Comment
Please, Sign In to add comment