diff --git a/src/Application/Application.java b/src/Application/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..55d8b2b6e5edd43b2d738d21865b25b0b9546758 --- /dev/null +++ b/src/Application/Application.java @@ -0,0 +1,412 @@ +package Application; + +import Contacts.Contacts; +import Family.Family; +import Friends.Friends; +import Helper.Helper; +import Professional.Professional; + +import java.util.Objects; +import java.util.Scanner; + +public class Application extends Helper { + Contacts[] contact_list; + + public void addToContactList(Contacts newContact) { + + // if null + if (contact_list == null) { + contact_list = new Contacts[1]; + contact_list[0] = newContact; + } else { + Contacts[] temp = new Contacts[contact_list.length + 1]; + + for (int i = 0; i < contact_list.length; i++) { + temp[i] = contact_list[i]; + } + temp[contact_list.length] = newContact; + + contact_list = temp; + // bubble sort + bubbleSort(); + } + } + + public Contacts createContact() { + + System.out.println("Enter the type of contact: []"); + System.out.println("[1] for friend "); + System.out.println("[2] for family "); + System.out.println("[3] for professional"); + System.out.println("Enter your choice [] :"); + + Scanner scanner = new Scanner(System.in); + int type = scanner.nextInt(); + while (type < 1 || type > 3) { + + System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT TYPE", RED); + System.out.format("%s", RESET); + System.out.println("Enter your choice [] :"); + type = scanner.nextInt(); + } + + Contacts new_contact = null; + if (type == 1) { + new_contact = new Friends() + .askContact(); + } + + else if (type == 2) { + new_contact = new Family().askContact(); + } + + else if (type == 3) { + new_contact = new Professional() + .askContact(); + } else { + PrintErrorAndReturn(); + } + // scanner.close(); + return new_contact; + + } + + public boolean update(int id) { + + int elementId = id - 1; + if (elementId >= 0 && elementId < contact_list.length) { + contact_list[elementId].updateContact(); + return true; + } + return false; + } + + public Contacts[] search() { + + Contacts[] result = new Contacts[0]; + Scanner scanner = new Scanner(System.in); + System.out.println("CHOOSE BY WHICH FIELD YOU WANT TO SEARCH"); + System.out.println("[1] NAME "); + System.out.println("[2] LASTNAME "); + System.out.println("[3] EMAIL"); + System.out.println("[4] BY TYPE:"); + + System.out.println(String.format("%s %s %s : []", BLUE, "YOUR FIELD ", BLUE)); + System.out.print(String.format("%s", RESET)); + int option = scanner.nextInt(); + while (option < 1 || option > 4) { + System.out.println(String.format("%s %s %s", RED, "ERREUR: PLEASE CHOOSE THE CORRECT FIELD", RED)); + System.out.println(String.format("%s %s %s : [] ", BLUE, "YOUR FIELD ", BLUE)); + System.out.print(String.format("%s", RESET)); + option = scanner.nextInt(); + } + + if (option == 1) { + + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A NAME TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + Scanner sc = new Scanner(System.in); + String nameToSearch = sc.nextLine(); + while (nameToSearch.length() < 3) { + System.out.println( + String.format("%s %s %s", RED, "NAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A NAME TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + nameToSearch = sc.nextLine(); + } + + int j = 0; + for (int i = 0; i < contact_list.length; i++) { + if (contact_list[i].getName().equals(nameToSearch)) { + result = new Contacts[result.length + 1]; + result[j++] = contact_list[i]; + } + } + } + + // } + if (option == 2) + + { + int j = 0; + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + Scanner sc = new Scanner(System.in); + String lastNameToSerach = sc.nextLine(); + while (lastNameToSerach.length() < 3) { + System.out.println( + String.format("%s %s %s", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + lastNameToSerach = sc.nextLine(); + } + + for (int i = 0; i < contact_list.length; i++) { + if (contact_list[i].getLastname().equals(lastNameToSerach)) { + result = new Contacts[result.length + 1]; + result[j++] = contact_list[i]; + } + } + } else if (option == 3) { + int j = 0; + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A EMAIL TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + Scanner sc = new Scanner(System.in); + String emailToSearch = sc.nextLine(); + while (emailToSearch.length() < 3) { + System.out.println( + String.format("%s %s %s\n", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A EMAIL TO SEARCH", BLUE)); + System.out.print(String.format("%s", RESET)); + emailToSearch = sc.nextLine(); + } + + for (int i = 0; i < contact_list.length; i++) { + if (contact_list[i].getEmailAddresses().equals(emailToSearch)) { + result = new Contacts[result.length + 1]; + result[j++] = contact_list[i]; + } + } + } else if (option == 4) { + int j = 0; + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A TYPE TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + Scanner sc = new Scanner(System.in); + String typeToSearch = sc.nextLine(); + while (typeToSearch.length() < 5) { + System.out.println( + String.format("%s %s %s\n", RED, "TYPE SHOULD CONTAINS AT LEAST 5 CHARACTER LENGTH", RED)); + System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A TYPE TO SEARCH ", BLUE)); + System.out.print(String.format("%s", RESET)); + typeToSearch = sc.nextLine(); + } + + for (int i = 0; i < contact_list.length; i++) { + if (contact_list[i].getType().equals(typeToSearch)) { + result = new Contacts[result.length + 1]; + result[j++] = contact_list[i]; + } + } + } + + return result; + } + + public boolean delete(int id) { + + int elementId = id - 1; + if (elementId >= 0 && elementId < contact_list.length) { + // delete + Contacts[] temp = new Contacts[contact_list.length - 1]; + + int j = 0; + for (int i = 0; i < contact_list.length; i++) { + if (i != elementId) { + temp[j] = contact_list[i]; + j++; + } + } + contact_list = temp; + return true; + + } else { + return false; + } + } + + public int getCharNumericValue(String value) { + return (int) (value.charAt(0)); + } + + public void shift(int index) { + Contacts tempContact = contact_list[index]; + contact_list[index] = contact_list[index - 1]; + contact_list[index - 1] = tempContact; + } + + public void bubbleSort() { + for (int i = 0; i < contact_list.length; i++) { + + for (int j = contact_list.length - 1; j >= 1; j--) { + + int firstPersonNameValue = getCharNumericValue(contact_list[j].getName().toUpperCase()); + int firstPersonLastNameValue = getCharNumericValue(contact_list[j].getLastname()[0].toUpperCase()); + + int secondPersonNameValue = getCharNumericValue(contact_list[j - 1].getName().toUpperCase()); + int secondPersonLastNameValue = getCharNumericValue(contact_list[j - 1].getLastname()[0].toUpperCase()); + + // sort by last name if first names are equals + if (firstPersonNameValue == secondPersonNameValue) { + + if (firstPersonLastNameValue < secondPersonLastNameValue) { + shift(j); + } + // sort by first name + } else if (firstPersonNameValue < secondPersonNameValue) { + shift(j); + } + + } + } + } + + public void showContacts() { + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", YELLOW); + PrintInColor(String.format("SHOW CONTACTS \t\t\t\t\t\t\tTOTAL [%s %d %s]\n", WHITE, + (contact_list != null) ? contact_list.length : 0, CYAN), CYAN); + PrintInColor("==================================================================================\n\n", YELLOW); + + if (contact_list == null) { + System.out.println(" No contacts yet !\n"); + } + + if (contact_list != null) { + for (int i = 0; i < contact_list.length; i++) { + + contact_list[i].showContact(); + } + } + } + + public void run() { + int option = ASK_USER_INPUT; + + while (true) { + Scanner scanner = new Scanner(System.in); + if (option == ASK_USER_INPUT) { + + PrintHeader(); + PrintInColor("Enter your option : ", WHITE); + + option = scanner.nextInt(); + + if (option == EXIT_CONSOLE) { + System.exit(0); + } + + if (option == ADD_CONTACTS) { + + addToContactList(createContact()); + option = ASK_USER_INPUT; + continue; + } + + if (option == SHOW_CONTACTS) { + showContacts(); + printFooter(); + + PrintInColor("Enter your option : ", WHITE); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + continue; + + } + + if (option == SEARCH_CONTACT) { + + if (contact_list != null) { + Contacts[] result = search(); + if (result.length != 0) { + for (int i = 0; i < result.length; i++) { + + result[i].showContact(); + } + printFooter(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + + } else { + System.out.println("---------------------------------------------------"); + System.out.println(String.format("no contact found")); + System.out.println("---------------------------------------------------"); + printFooter(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + } else { + showContacts(); + printFooter(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + + } + continue; + } + + // update contact + if (option == UPDATE_CONTACTS) { + + showContacts(); + if (contact_list != null) { + + System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); + int id = scanner.nextInt(); + + while (id < 1 || id > contact_list.length + 1) { + System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT ID", RED); + System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); + id = scanner.nextInt(); + } + + Boolean updated = update(id); + if (updated) { + option = ASK_USER_INPUT; + } else { + System.out.println(String.format( + " Contact with id %d doesn't exists", id)); + PrintErrorAndReturn(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + + } else { + showContacts(); + printFooter(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + continue; + } + // delete contact + if (option == DELETE_CONTACT) { + showContacts(); + + if (contact_list != null) { + deleteOption(); + System.out.print("Enter contact id to delete: "); + int id = scanner.nextInt(); + + boolean deleted = delete(id); + + if (deleted) { + option = ASK_USER_INPUT; + } else { + System.out.println(String.format( + " Contact with id %d doesn't exists", id)); + PrintErrorAndReturn(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + + } else { + printFooter(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + continue; + } + + } + + if (option < 1 || option > 4) { + + clearConsoleScreen(); + PrintErrorAndReturn(); + option = scanner.nextInt(); + option = populateErrorOrReturnHome(option); + } + scanner.close();// close scanner + } + } +} diff --git a/src/Contacts/Contacts.java b/src/Contacts/Contacts.java new file mode 100644 index 0000000000000000000000000000000000000000..81c7cf7eabccdf0828590bda082c42ce881b8d95 --- /dev/null +++ b/src/Contacts/Contacts.java @@ -0,0 +1,253 @@ +package Contacts; + +import Helper.Helper; + +import java.util.Scanner; + +public abstract class Contacts extends Helper { + + protected String name; + protected String[] lastname; + protected String address; + protected String[] telelphoneNumbers; + protected String[] emailAddresses; + protected String[] socialAcounts; + protected String profession; + + public Contacts() { + } + + public Contacts(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, + String[] socialAcounts, String profession) { + this.name = name; + this.lastname = lastname; + this.address = address; + this.telelphoneNumbers = telelphoneNumbers; + this.emailAddresses = emailAddresses; + this.socialAcounts = socialAcounts; + this.profession = profession; + } + + public String getName() { + return name; + } + + protected void setName(String name) { + this.name = name; + } + + public String[] getLastname() { + return lastname; + } + + public void setLastname(String[] lastname) { + this.lastname = lastname; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String[] getTelelphoneNumbers() { + return telelphoneNumbers; + } + + public void setTelelphoneNumbers(String[] telelphoneNumbers) { + this.telelphoneNumbers = telelphoneNumbers; + } + + public String[] getEmailAddresses() { + return emailAddresses; + } + + public void setEmailAddresses(String[] emailAddresses) { + this.emailAddresses = emailAddresses; + } + + public String[] getSocialAcounts() { + return socialAcounts; + } + + public void setSocialAcounts(String[] socialAcounts) { + this.socialAcounts = socialAcounts; + } + + public String getProfession() { + return profession; + } + + public void setProfession(String profession) { + this.profession = profession; + } + + public void askName() { + + Scanner sc = new Scanner(System.in); + + System.out.print(" Enter a name [] : "); + String name = sc.nextLine(); + while (name.length() < 3) { + System.out + .println( + String.format("\n %sName should contain at least 3 character %s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter a name [] : "); + name = sc.nextLine(); + } + setName(name); + // sc.close(); + } + + public void askLastName() { + + Scanner sc = new Scanner(System.in); + + System.out.print(" Enter one or more last name separated by , [] : "); + String lastName = sc.nextLine(); + + while (lastName.length() < 3) { + System.out + .println( + String.format("\n %slast name should contain at least 3 character %s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter one or more last name separated by , [] : "); + name = sc.nextLine(); + } + setLastname(lastName.split(",")); + + // sc.close(); + } + + public void askAdress() { + Scanner sc = new Scanner(System.in); + + System.out.print(" Enter Address [] : "); + String address = sc.nextLine(); + while (address.length() < 15) { + System.out + .println( + String.format("\n %sAddress should at least contain 15 character length%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter Address [] : "); + address = sc.nextLine(); + } + setAddress(address); + + // sc.close(); + } + + public void askEmail() { + Scanner sc = new Scanner(System.in); + System.out.print(" Enter one or more email separated by , [] : "); + String email = sc.nextLine(); + + while (email.length() < 10 || !email.contains("@") || !email.contains(".")) { + System.out + .println( + String.format("\n %sPlease Insert a correct Email !%s%s", RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter one or more email separated by , [] : "); + + email = sc.nextLine(); + } + setEmailAddresses(email.split(",")); + // sc.close(); + } + + public void askTelephoneNumber() { + Scanner sc = new Scanner(System.in); + + System.out.print(" Enter one or more telephone number separated by , [] : "); + String telephonNumber = sc.nextLine(); + + while (telephonNumber.length() < 12 || !telephonNumber.contains("+") + || telephonNumber.replaceAll(" ", telephonNumber).length() < 12) { // +4178 223 22 44 + System.out.println( + String.format("\n %sPLEASE INSERT A CORRECT TELEPHONE NUMBER !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter one or more telephone number separated by , [] : "); + telephonNumber = sc.nextLine(); + + } + setTelelphoneNumbers(telephonNumber.split(",")); + + // sc.close(); + } + + public void askSocialAcount() { + Scanner sc = new Scanner(System.in); + System.out.print(" Enter one or more social acount URL separated by , [] :"); + String socialAcount = sc.nextLine(); + + while (!socialAcount.contains("https://")) { + System.out + .println( + String.format("\n %sPLEASE INSERT A CORRECT URL PREFIXED BY HTTPS:// !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter one or more social acount URL separated by , [] :"); + socialAcount = sc.nextLine(); + } + setSocialAcounts(socialAcount.split(",")); + // sc.close(); + } + + public void askProfession() { + + Scanner sc = new Scanner(System.in); + System.out.print(" Enter Your Contact Profession [] : "); + String profession = sc.nextLine(); + + while (profession.length() < 5) { + System.out + .println( + String.format("\n %sPLEASE INSERT A CORRECT PROFESSION !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter Your Contact Profession [] : "); + profession = sc.nextLine(); + } + setProfession(profession); + // sc.close(); + } + + public void displayRequestHeader() { + + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "CREATE A CONTACT"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + } + + public abstract String getType(); + + public abstract void setType(String type); + + public abstract void showContact(); + + public abstract void updateContact(); + +} diff --git a/src/Family/Family.java b/src/Family/Family.java new file mode 100644 index 0000000000000000000000000000000000000000..6a3427b23b1befcfbabfcd2251d9ecd9f13174a5 --- /dev/null +++ b/src/Family/Family.java @@ -0,0 +1,190 @@ +package Family; + +import java.util.Scanner; + +import Contacts.Contacts; +import Helper.Helper; + +public class Family extends Contacts { + private String Type; + private String familyRelation; + + public Family() { + super(); + this.Type = "Family"; + } + + public Family(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, + String[] socialAcounts, String profession, String familyRelation) { + super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + Type = "Family"; + setFamilyRelation(familyRelation); + } + + @Override + public String getType() { + return Type; + } + + @Override + public void setType(String type) { + Type = type; + } + + public void setFamilyRelation(String familyRelation) { + this.familyRelation = familyRelation; + } + + public String getFamilyRelation() { + return this.familyRelation; + } + + public void askFamilyRelation() { + + Scanner sc = new Scanner(System.in); + System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); + String famRelation = sc.nextLine(); + + while (famRelation.length() < 5) { + System.out + .println( + String.format("\n %sPLEASE INSERT A CORRECT FAMILY RELATION !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); + famRelation = sc.nextLine(); + } + setFamilyRelation(famRelation); + + } + + public Family askContact() { + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "CREATE A CONTACT [Family]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + askName(); + askLastName(); + askEmail(); + // + askFamilyRelation(); + askTelephoneNumber(); + askAdress(); + + askSocialAcount(); + askProfession(); + return this; + + } + public void updateContact(){ + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "UPDATE CONTACT [Family]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); + System.out.println("[1] NAME "); + System.out.println("[2] LASTNAME "); + System.out.println("[3] EMAIL"); + System.out.println("[4] FAMILY RELATION:"); + System.out.println("[5] TELEPHONE NUMBER:"); + System.out.println("[6] ADDRESS:"); + System.out.println("[7] SOCIAL ACOUNT:"); + System.out.println("[8] PROFESSION:"); + + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + Scanner sc = new Scanner(System.in); + int option = sc.nextInt(); + while(option < 1 || option > 8){ + System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); + System.out.format("%s", RESET); + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + option = sc.nextInt(); + } + + switch (option){ + case 1: + askName(); + break; + case 2: + askLastName(); + break; + case 3: + askEmail(); + break; + case 4: + askFamilyRelation(); + break; + case 5: + askTelephoneNumber(); + break; + case 6: + askAdress(); + break; + case 7: + askSocialAcount(); + break; + case 8: + askProfession(); + break; + } + } + + + @Override + public void showContact() { + + System.out.println( + "----------------------------------------------------------------------------------"); + System.out.println(); + + System.out.println(String.format(" %sName : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getName(), RESET)); + + System.out.println(); + String lastnames = String.join(",", getLastname()); + System.out.println(String.format(" %sLast Name : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + lastnames, RESET)); + + System.out.println(); + System.out.println(String.format(" %sFamily Relation : %s", BLUE, + BLUE) + + String.format("\t\t%s" + getFamilyRelation(), RESET)); + + System.out.println(); + System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getAddress(), RESET)); + + System.out.println(); + String emails = String.join(", ", getEmailAddresses()); + System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + emails, RESET)); + + System.out.println(); + String telephone_numbers = String.join(", ", getTelelphoneNumbers()); + System.out.println(String.format(" %sTelephone Number : %s", BLUE, + BLUE) + + String.format("\t\t%s" + telephone_numbers, RESET)); + + System.out.println(); + String social_acounts = String.join(", ", getSocialAcounts()); + System.out.println(String.format(" %sSocial Acount : %s", BLUE, + BLUE) + + String.format("%s" + social_acounts, RESET)); + + System.out.println(); + System.out.println(String.format(" %sProfession : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + getProfession(), RESET)); + + System.out.println(); + System.out.println( + "----------------------------------------------------------------------------------\n"); + + } + +} diff --git a/src/Friends/Friends.java b/src/Friends/Friends.java new file mode 100644 index 0000000000000000000000000000000000000000..e8c01462ce6a26e837f7a3cc1c6716e0d73e88c2 --- /dev/null +++ b/src/Friends/Friends.java @@ -0,0 +1,192 @@ +package Friends; + +import Contacts.Contacts; +import Family.Family; +import Professional.Professional; + +import java.util.Scanner; + +public class Friends extends Contacts { + + private String Type; + + private String firendsSince; + + public Friends() { + super(); + Type = "Friend"; + } + + public Friends(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, + String[] socialAcounts, String profession, String firendsSince) { + super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + Type = "Friend"; + setFriendsSince(firendsSince); + } + + @Override + public String getType() { + return Type; + } + + @Override + public void setType(String type) { + Type = type; + } + + public void setFriendsSince(String str) { + this.firendsSince = str; + + } + + public String getFriendsSince() { + return this.firendsSince; + } + + public void askFriendShipDate() { + + Scanner sc = new Scanner(System.in); + System.out.print(this.name + " is Your friend since : "); + String friendshipeDate = sc.nextLine(); + + while (friendshipeDate.length() < 5) { + System.out + .println( + String.format("\n %sPLEASE INSERT A CORRECT FRIENDSHIP DATE !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out.print(this.name + " is Your friend since : "); + friendshipeDate = sc.nextLine(); + } + setFriendsSince(friendshipeDate); + } + + public Contacts askContact() { + + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "CREATE A CONTACT [Friends]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + askName(); + askLastName(); + askEmail(); + // + askFriendShipDate(); + askTelephoneNumber(); + askAdress(); + askSocialAcount(); + askProfession(); + return this; + + } + + public void updateContact(){ + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "UPDATE CONTACT [FRIENDS]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); + System.out.println("[1] NAME "); + System.out.println("[2] LASTNAME "); + System.out.println("[3] EMAIL"); + System.out.println("[4] FRIENDSHIP DATE:"); + System.out.println("[5] TELEPHONE NUMBER:"); + System.out.println("[6] ADDRESS:"); + System.out.println("[7] SOCIAL ACOUNT:"); + System.out.println("[8] PROFESSION:"); + + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + Scanner sc = new Scanner(System.in); + int option = sc.nextInt(); + while(option < 1 || option > 8){ + System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); + System.out.format("%s", RESET); + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + option = sc.nextInt(); + } + + switch (option){ + case 1: + askName(); + break; + case 2: + askLastName(); + break; + case 3: + askEmail(); + break; + case 4: + askFriendShipDate(); + break; + case 5: + askTelephoneNumber(); + break; + case 6: + askAdress(); + break; + case 7: + askSocialAcount(); + break; + case 8: + askProfession(); + break; + } + } + + @Override + public void showContact() { + + System.out.println( + "----------------------------------------------------------------------------------"); + System.out.println(); + + System.out.println(String.format(" %sName : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getName(), RESET)); + + System.out.println(); + String lastnames = String.join(",", getLastname()); + System.out.println(String.format(" %sLast Name : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + lastnames, RESET)); + + System.out.println(); + System.out.println(String.format(" %sFriendship since : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + getFriendsSince(), RESET)); + + System.out.println(); + System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getAddress(), RESET)); + + System.out.println(); + String emails = String.join(", ", getEmailAddresses()); + System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + emails, RESET)); + + System.out.println(); + String telephone_numbers = String.join(", ", getTelelphoneNumbers()); + System.out.println(String.format(" %sTelephone Number : %s", BLUE, + BLUE) + + String.format("\t\t%s" + telephone_numbers, RESET)); + + System.out.println(); + String social_acounts = String.join(", ", getSocialAcounts()); + System.out.println(String.format(" %sSocial Acount : %s", BLUE, + BLUE) + + String.format("\t\t%s" + social_acounts, RESET)); + + System.out.println(); + System.out.println(String.format(" %sProfession : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + getProfession(), RESET)); + + System.out.println(); + System.out.println( + "----------------------------------------------------------------------------------\n"); + + } +} diff --git a/src/Helper/Helper.java b/src/Helper/Helper.java new file mode 100644 index 0000000000000000000000000000000000000000..762e26ccb36137ef5ce216719efbd7a6ceed98bd --- /dev/null +++ b/src/Helper/Helper.java @@ -0,0 +1,115 @@ +package Helper; + + + +public abstract class Helper { + + // text color + protected final String RED = "\u001B[31m"; + protected final String BLACK = "\u001B[30m"; + protected final String GREEN = "\u001B[32m"; + protected final String BLUE = "\u001B[34m"; + protected final String RESET = "\u001B[0m"; + protected final String PURPLE = "\u001B[35m"; + protected final String CYAN = "\u001B[36m"; + protected final String YELLOW = "\u001B[33m"; + protected final String WHITE = "\u001B[37m"; + + protected final String YELLOW_BACKGROUND = "\u001B[43m"; + protected final String BLUE_BACKGROUND = "\u001B[44m"; + protected final String BLACK_BACKGROUND = "\u001B[40m"; + protected final String PURPLE_BACKGROUND = "\u001B[45m"; + protected final String CYAN_BACKGROUND = "\u001B[46m"; + protected final String GREEN_BACKGROUND = "\u001B[42m"; + protected final String WHITE_BACKGROUND = "\u001B[47m"; + + protected final int ASK_USER_INPUT = 110; + protected final int SHOW_CONTACTS = 1; + protected final int ADD_CONTACTS = 2; + protected final int SEARCH_CONTACT = 3; + protected final int UPDATE_CONTACTS = 4; + protected final int DELETE_CONTACT = 5; + protected final int EXIT_CONSOLE = 6; + + // clear console screen + protected void clearConsoleScreen() { + System.out.print("\033[H\033[2J"); + System.out.flush(); + } + + // print in color a given text or change background color + protected void PrintInColor(String text, String color) { + + System.out.format("%s %s %s", color, text, color); + System.out.format("%s", RESET); + } + + // Print header of our console application + protected void PrintHeader() { + + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", + YELLOW); + PrintInColor("WELLCOME TO CONTACT MANAGEMENT SYSTEM \n", GREEN); + PrintInColor("==================================================================================\n", + YELLOW); + + PrintInColor("[1]: \tshow contacts\t\t\t\t\n", CYAN); + PrintInColor("[2]: \tadd contact\t\t\t\t\n", CYAN); + PrintInColor("[3]: \tsearch contact\t\t\t\t\n", CYAN); + PrintInColor("[4]: \tupdate a contact\t\t\t\t\n", CYAN); + PrintInColor("[5]: \tdelete a contact\t\t\t\t\n", CYAN); + PrintInColor("[6]: \texit\t\t\t\t\n", CYAN); + PrintInColor("==================================================================================\n", + YELLOW); + } + + // print OPTION ERROR + protected void PrintErrorAndReturn() { + + PrintInColor(" ----------------------------------------------------------------------------------\n", + YELLOW); + PrintInColor("ERROR: WRONG OPTION ID \n", RED); + PrintInColor("----------------------------------------------------------------------------------\n", + YELLOW); + + PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); + PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); + PrintInColor("----------------------------------------------------------------------------------\n", + YELLOW); + + } + + protected void printFooter() { + + PrintInColor(" ----------------------------------------------------------------------------------\n", + YELLOW); + PrintInColor("RETURN TO HOME \n", CYAN); + PrintInColor("----------------------------------------------------------------------------------\n", + YELLOW); + + PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); + PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); + PrintInColor("----------------------------------------------------------------------------------\n", + YELLOW); + } + + protected void deleteOption() { + PrintInColor(" ==================================================================================\n", + YELLOW); + PrintInColor("DELETE A CONCTACT\n", CYAN); + PrintInColor("==================================================================================\n", + YELLOW); + } + + protected int populateErrorOrReturnHome(int option) { + if (option == 1) { + return ASK_USER_INPUT; + } + if (option == 2) { + System.exit(0); + } + return 0; + } + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..76fcf5efd30d4a36b5489669eb16a026f3e16c39 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,7 @@ +import Application.Application; + +public class Main { + public static void main(String[] args) { + new Application().run(); + } +} \ No newline at end of file diff --git a/src/Professional/Professional.java b/src/Professional/Professional.java new file mode 100644 index 0000000000000000000000000000000000000000..7374f142fe764c343f1fdc0c62e9a9a627a89f90 --- /dev/null +++ b/src/Professional/Professional.java @@ -0,0 +1,191 @@ +package Professional; + +import java.util.Scanner; + +import Contacts.Contacts; +import Family.Family; + +public class Professional extends Contacts { + private String Type; + + private String ProfessionRelation; + + public Professional() { + super(); + Type = "Professional"; + } + + public Professional(String name, String[] lastname, String address, String[] telelphoneNumbers, + String[] emailAddresses, String[] socialAcounts, String profession, String professionRelation) { + super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + setProfessionRelation(professionRelation); + Type = "Professional"; + } + + @Override + public String getType() { + return Type; + } + + @Override + public void setType(String type) { + Type = type; + } + + public void setProfessionRelation(String professionRelation) { + ProfessionRelation = professionRelation; + } + + public String getProfessionalRelation() { + return this.ProfessionRelation; + } + + public void askProfessionalRelation() { + + Scanner sc = new Scanner(System.in); + System.out.print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); + String proRelation = sc.nextLine(); + + while (proRelation.length() < 5) { + System.out + .println( + String.format("\n %sPLEASE INSERT A CORRECT PROFESSIONAL RELATION !%s%s", + RED, + RED, + RESET)); + System.out.println(); + System.out + .print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); + proRelation = sc.nextLine(); + } + setProfessionRelation(proRelation); + + } + + public Professional askContact() { + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "CREATE A CONTACT [Professional]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + askName(); + askLastName(); + askEmail(); + // + askProfessionalRelation(); + askTelephoneNumber(); + askAdress(); + askSocialAcount(); + askProfession(); + + return this; + + } + + public void updateContact(){ + clearConsoleScreen(); + PrintInColor(" ==================================================================================\n", GREEN); + PrintInColor(String.format("%s\n", "UPDATE CONTACT [PROFESSIONAL]"), BLUE); + PrintInColor("==================================================================================\n", GREEN); + + System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); + System.out.println("[1] NAME "); + System.out.println("[2] LASTNAME "); + System.out.println("[3] EMAIL"); + System.out.println("[4] PROFESSIONAL RELATION:"); + System.out.println("[5] TELEPHONE NUMBER:"); + System.out.println("[6] ADDRESS:"); + System.out.println("[7] SOCIAL ACOUNT:"); + System.out.println("[8] PROFESSION:"); + + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + Scanner sc = new Scanner(System.in); + int option = sc.nextInt(); + while(option < 1 || option > 8){ + System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); + System.out.format("%s", RESET); + System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); + option = sc.nextInt(); + } + + switch (option){ + case 1: + askName(); + break; + case 2: + askLastName(); + break; + case 3: + askEmail(); + break; + case 4: + askProfessionalRelation(); + break; + case 5: + askTelephoneNumber(); + break; + case 6: + askAdress(); + break; + case 7: + askSocialAcount(); + break; + case 8: + askProfession(); + break; + } + } + + @Override + public void showContact() { + + System.out.println( + "----------------------------------------------------------------------------------"); + System.out.println(); + + System.out.println(String.format(" %sName : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getName(), RESET)); + + System.out.println(); + String lastnames = String.join(",", getLastname()); + System.out.println(String.format(" %sLast Name : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + lastnames, RESET)); + + System.out.println(); + System.out.println(String.format(" %sProfessional Relation : %s", BLUE, + BLUE) + + String.format("\t\t%s" + getProfessionalRelation(), RESET)); + + System.out.println(); + System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + getAddress(), RESET)); + + System.out.println(); + String emails = String.join(", ", getEmailAddresses()); + System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) + + String.format("\t\t\t%s" + emails, RESET)); + + System.out.println(); + String telephone_numbers = String.join(", ", getTelelphoneNumbers()); + System.out.println(String.format(" %sTelephone Number : %s", BLUE, + BLUE) + + String.format("\t\t%s" + telephone_numbers, RESET)); + + System.out.println(); + String social_acounts = String.join(", ", getSocialAcounts()); + System.out.println(String.format(" %sSocial Acount : %s", BLUE, + BLUE) + + String.format("\t\t%s" + social_acounts, RESET)); + + System.out.println(); + System.out.println(String.format(" %sProfession : %s", BLUE, + BLUE) + + String.format("\t\t\t%s" + getProfession(), RESET)); + + System.out.println(); + System.out.println( + "----------------------------------------------------------------------------------\n"); + + } +}