Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a class called Contact. This class should contain information of a single

ID: 3817551 • Letter: W

Question

write a class called Contact. This class should contain information of a single personal contact. The information includes last name, first name, address, phone, and e-mail address. For now you can store an address as a string. Your class should support the following functions: 1. Constructor that initializes a Contact by accepting all the parameters. 2. Default constructor that initializes everything to default values. 3. Accessor functions for each field. 4. Mutator functions for each field. 5. Input function to solicit the information. 6. Output function to print out the information about the contact to console in a nice format. 7. Any other necessary functions you feel are appropriate. Make sure the mutator functions accept correct formats of both email and phone number. (i.e. e-mail must be of the form [e-mail-account]@[domain-name].[top-level-domain]. Phone number should be a string of 10 digits) write a class called Contact. This class should contain information of a single personal contact. The information includes last name, first name, address, phone, and e-mail address. For now you can store an address as a string. Your class should support the following functions: 1. Constructor that initializes a Contact by accepting all the parameters. 2. Default constructor that initializes everything to default values. 3. Accessor functions for each field. 4. Mutator functions for each field. 5. Input function to solicit the information. 6. Output function to print out the information about the contact to console in a nice format. 7. Any other necessary functions you feel are appropriate. Make sure the mutator functions accept correct formats of both email and phone number. (i.e. e-mail must be of the form [e-mail-account]@[domain-name].[top-level-domain]. Phone number should be a string of 10 digits) write a class called Contact. This class should contain information of a single personal contact. The information includes last name, first name, address, phone, and e-mail address. For now you can store an address as a string. Your class should support the following functions: 1. Constructor that initializes a Contact by accepting all the parameters. 2. Default constructor that initializes everything to default values. 3. Accessor functions for each field. 4. Mutator functions for each field. 5. Input function to solicit the information. 6. Output function to print out the information about the contact to console in a nice format. 7. Any other necessary functions you feel are appropriate. Make sure the mutator functions accept correct formats of both email and phone number. (i.e. e-mail must be of the form [e-mail-account]@[domain-name].[top-level-domain]. Phone number should be a string of 10 digits)

Explanation / Answer

Hi Friend, You have not mentioned about programming language.

Please try to provide all details.

I have implemented in Java.

Please let me know in case of any issue.

public class Contact {

  

   // instance variables

   private String firstName;

   private String lastName;

   private String address;

   private String phone;

   private String email;

  

   public Contact() {

       setFirstName("");

       setLastName("");

       setAddress("");

       setPhone("1234567890");

       setEmail("demo@ayx.com");

   }

   public Contact(String firstName, String lastName, String address, String phone, String email) {

      

       setFirstName(firstName);

       setLastName(lastName);

       setAddress(address);

       setPhone(phone);

       setEmail(email);

   }

   public String getFirstName() {

       return firstName;

   }

   public String getLastName() {

       return lastName;

   }

   public String getAddress() {

       return address;

   }

   public String getPhone() {

       return phone;

   }

   public String getEmail() {

       return email;

   }

   public void setFirstName(String firstName) {

       this.firstName = firstName;

   }

   public void setLastName(String lastName) {

       this.lastName = lastName;

   }

   public void setAddress(String address) {

       this.address = address;

   }

   public void setPhone(String phone) {

      

       if(phone == null)

           throw new IllegalArgumentException("Phone can not be null");

      

       if(phone.length() != 10)

           throw new IllegalArgumentException("Phone Number shoud be of 10 length");

       this.phone = phone;

   }

   public void setEmail(String email) {

      

       if(email == null)

           throw new IllegalArgumentException("Email can not be null");

       // finding the index of . and @

       int index = email.indexOf('.');

       int index1 = email.indexOf('@');

      

       if(index == -1)

           throw new IllegalArgumentException("Email should contains (dot)");

      

       if(index1 == -1)

           throw new IllegalArgumentException("Email should contains @");

      

        this.email = email;

   }

  

   @Override

   public String toString() {

       return "Name: "+firstName+" "+lastName+" "+

               "Address: "+address+" "+

               "Phone: "+phone+" "+

               "Email: "+email;

   }

  

  

   public static void main(String[] args) {

      

       Contact c1 = new Contact("Pravesh", "Kumar", "Bangalore-0987", "4321256787", "test@demo.com");

      

       System.out.println(c1);

   }

}

/*

Sample run:

Name: Pravesh Kumar

Address: Bangalore-0987

Phone: 4321256787

Email: test@demo.com

*/