summaryrefslogtreecommitdiff
path: root/src/Q1/AddressBook.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q1/AddressBook.java')
-rw-r--r--src/Q1/AddressBook.java383
1 files changed, 0 insertions, 383 deletions
diff --git a/src/Q1/AddressBook.java b/src/Q1/AddressBook.java
deleted file mode 100644
index 2c1b9a6..0000000
--- a/src/Q1/AddressBook.java
+++ /dev/null
@@ -1,383 +0,0 @@
-/**
- * Assignment 1, COMP268 Class: AddressBook.java
- *
- * @description Represents a contact from an address book.
- * @author: mo khan Student ID: 3431709
- * @date May 6, 2019
- * @version 1.0
- */
-package Q1;
-
-import java.util.Objects;
-import java.util.Scanner;
-
-public class AddressBook implements Comparable<AddressBook> {
- private String businessPhone;
- private String cellPhone;
- private String facebookId;
- private String firstName = "";
- private String homeAddress;
- private String homePhone;
- private String lastName = "";
- private String middleName = "";
- private String personalWebSite;
- private String skypeId;
-
- /** Create a new instance of class AddressBook. Initialize all fields to a blank string. */
- public AddressBook() {
- this("");
- }
-
- /**
- * Create a new instance of class AddressBook. Initialize the firstName and set all other fields
- * to a blank string.
- *
- * @param firstName the first name for the contact.
- */
- public AddressBook(String firstName) {
- this(firstName, "", "");
- }
-
- /**
- * Create a new instance of class AddressBook. Initialize the first name, middle name and last
- * name. Set all other fields to a blank string.
- *
- * @param firstName the first name of the contact.
- * @param middleName the middle name of the contact.
- * @param lastName the last name of the contact.
- */
- public AddressBook(String firstName, String middleName, String lastName) {
- this(firstName, middleName, lastName, "", "", "", "", "", "", "");
- }
-
- /**
- * Create a new instance of class AddressBook. Initialize the first name, middle name, last name,
- * business phone number, cell phone number, Facebook Id, home address, home phone number,
- * personal website and Skype Id of the contact.
- *
- * @param firstName the first name of the contact.
- * @param middleName the middle name of the contact.
- * @param lastName the last name of the contact.
- * @param businessPhone the phone number of the contact.
- * @param cellPhone the cell phone number of the contact.
- * @param facebookId the Facebook Id of the contact.
- * @param homeAddress the home address of the contact.
- * @param homePhone the home phone number of the contact.
- * @param personalWebSite the website of the contact.
- * @param skypeId the Skype Id of the contact.
- */
- public AddressBook(
- String firstName,
- String middleName,
- String lastName,
- String businessPhone,
- String cellPhone,
- String facebookId,
- String homeAddress,
- String homePhone,
- String personalWebSite,
- String skypeId) {
- this.businessPhone = businessPhone;
- this.cellPhone = cellPhone;
- this.facebookId = facebookId;
- this.firstName = firstName;
- this.homeAddress = homeAddress;
- this.homePhone = homePhone;
- this.lastName = lastName;
- this.middleName = middleName;
- this.personalWebSite = personalWebSite;
- this.skypeId = skypeId;
- }
-
- /**
- * Returns the business phone number.
- *
- * @return the business phone number.
- */
- public String getBusinessPhone() {
- return this.businessPhone;
- }
-
- /**
- * Returns the cell phone number.
- *
- * @return the cell phone number.
- */
- public String getCellPhone() {
- return this.cellPhone;
- }
-
- /**
- * Returns the Facebook Id.
- *
- * @return the Facebook Id
- */
- public String getFacebookId() {
- return this.facebookId;
- }
-
- /**
- * Returns the first name.
- *
- * @return the first name
- */
- public String getFirstName() {
- return this.firstName;
- }
-
- /**
- * Returns the home address.
- *
- * @return the home address
- */
- public String getHomeAddress() {
- return this.homeAddress;
- }
-
- /**
- * Returns the home phone number.
- *
- * @return the phone number
- */
- public String getHomePhone() {
- return this.homePhone;
- }
-
- /**
- * Returns the last name.
- *
- * @return the last name
- */
- public String getLastName() {
- return this.lastName;
- }
-
- /**
- * Returns the middle name.
- *
- * @return the middle name
- */
- public String getMiddleName() {
- return this.middleName;
- }
-
- /**
- * Returns the personal website.
- *
- * @return the website name
- */
- public String getPersonalWebSite() {
- return this.personalWebSite;
- }
-
- /**
- * Returns the Skype Id.
- *
- * @return the skype id
- */
- public String getSkypeId() {
- return this.skypeId;
- }
-
- /**
- * Sets the business phone number.
- *
- * @param value The new phone number.
- */
- public void setBusinessPhone(String value) {
- this.businessPhone = value;
- }
-
- /**
- * Sets the cell phone number.
- *
- * @param value The new cell phone number.
- */
- public void setCellPhone(String value) {
- this.cellPhone = value;
- }
-
- /**
- * Sets the Facebook Id.
- *
- * @param value The new Facebook id.
- */
- public void setFacebookId(String value) {
- this.facebookId = value;
- }
-
- /**
- * Sets the first name.
- *
- * @param name the new first name.
- */
- public void setFirstName(String name) {
- this.firstName = name;
- }
-
- /**
- * Sets the home address.
- *
- * @param address new home address.
- */
- public void setHomeAddress(String address) {
- this.homeAddress = address;
- }
-
- /**
- * Sets the home phone number.
- *
- * @param value the new home phone number.
- */
- public void setHomePhone(String value) {
- this.homePhone = value;
- }
-
- /**
- * Sets the last name.
- *
- * @param name the last name.
- */
- public void setLastName(String name) {
- this.lastName = name;
- }
-
- /**
- * Sets the middle name.
- *
- * @param name the middle name.
- */
- public void setMiddleName(String name) {
- this.middleName = name;
- }
-
- /**
- * Sets the personal website.
- *
- * @param value the personal website
- */
- public void setPersonalWebSite(String value) {
- this.personalWebSite = value;
- }
-
- /**
- * Sets the Skype Id.
- *
- * @param value the Skype Id.
- */
- public void setSkypeId(String value) {
- this.skypeId = value;
- }
-
- /**
- * Converts a name to an Address Book.
- *
- * @param name the name to parse.
- * @return an AddressBook instance.
- */
- public static AddressBook parseFrom(String name) {
- String[] parts = name.split(" ");
-
- switch (parts.length) {
- case 1:
- return new AddressBook(parts[0]);
- case 2:
- return new AddressBook(parts[0], "", parts[1]);
- case 3:
- return new AddressBook(parts[0], parts[1], parts[2]);
- default:
- return new AddressBook();
- }
- }
-
- /**
- * Compares name1 with name2 and returns a string representation. Returns a negative value if
- * name1 is less than name2. Returns a positive value if name1 is greater than name2. Returns a
- * zero if name1 is equal to name2.
- *
- * @param name1 first name
- * @param name2 second name
- * @return string version of -1, 0, 1
- */
- public static String compareNames(String name1, String name2) {
- return Integer.toString(parseFrom(name1).compareTo(parseFrom(name2)));
- }
-
- /**
- * Compares one address book with another. Returns a negative value if this is less than other.
- * Returns a positive value if this is greater than other. Returns a zero if this is equal to
- * other.
- *
- * @param other The other address book to compare to.
- */
- public int compareTo(AddressBook other) {
- return this.firstName.compareTo(other.firstName)
- + this.middleName.compareTo(other.middleName)
- + this.lastName.compareTo(other.lastName);
- }
-
- /**
- * Overrides equals to check for value equality instead of reference equality.
- *
- * @param o The other item to check against.
- * @return true if values match, otherwise false.
- */
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof AddressBook)) return false;
- AddressBook that = (AddressBook) o;
- return Objects.equals(businessPhone, that.businessPhone)
- && Objects.equals(cellPhone, that.cellPhone)
- && Objects.equals(facebookId, that.facebookId)
- && Objects.equals(firstName, that.firstName)
- && Objects.equals(homeAddress, that.homeAddress)
- && Objects.equals(homePhone, that.homePhone)
- && Objects.equals(lastName, that.lastName)
- && Objects.equals(middleName, that.middleName)
- && Objects.equals(personalWebSite, that.personalWebSite)
- && Objects.equals(skypeId, that.skypeId);
- }
-
- /**
- * Overrides hashCode to ensure instances that are equal by value equate to the same hash code for
- * hash key computations.
- *
- * @return The hash code
- */
- @Override
- public int hashCode() {
- return Objects.hash(
- businessPhone,
- cellPhone,
- facebookId,
- firstName,
- homeAddress,
- homePhone,
- lastName,
- middleName,
- personalWebSite,
- skypeId);
- }
-
- /**
- * Overrides toString to return the first name of the contact.
- *
- * @return the first name of the contact.
- */
- @Override
- public String toString() {
- return this.firstName;
- }
-
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("Please enter first name: ");
- String first = in.next();
-
- System.out.print("Please enter second name: ");
- String second = in.next();
-
- System.out.println("The comparison result is " + AddressBook.compareNames(first, second));
- }
-}