Code Monkey home page Code Monkey logo

contact-book's Introduction

Contact Book

The purpose of this exercise is to train using nested classes.

Estimated workload of this exercise is 60 min.

Description

In this exercise we are going to manage contacts information.

A Contact is a class containing different information of how to reach a person or a company: phone number, emails, social media.

A contact has a name, which is provided via the class constructor. Also, a contact contains limited amount of entries:

  • a phone number (only a single one)
  • emails (up to 3 entries)
  • social media links (up to 5 entries)

A contact info entry is described with ContactInfo interface. Each entry has a title and a value. You need to implemented them as nested classes of the Contact class:

  • Contact.NameContactInfo - A ContactInfo implementation providing the name of the contact. Implement as private non-static nested class. Use "Name" for the entry title. It must not have its own fields. It must use fields of the bounded Contact instance instead.
  • Contact.Email - A ContactInfo implementation containing an email. Implement as public static nested class. Use "Email" for the entry title.
  • Contact.Social - A ContactInfo implementation containing a social media link/id. Implement as public static nested class. Let the user of the class define the title.
  • Other implementations must be anonymous. Do not provide other non-anonymous classes.

It is possible to add contact info entries via add* methods. All such methods return the created entry as the result, null if nothing was added to the contact.

  • addEmail(String localPart, String domain)
    Adds an email entry.
    addEmail("someone", "somewhere.com").getValue() will result to [email protected].
  • addEpamEmail(String firstname, String lastname)
    Adds a special email entry with "epam.com" domain. Please, implement this method using an anonymous extension of the Email class. Use "Epam Email" for the entry title.
    addEpamEmail("some", "one").getValue() will result to [email protected]
  • addPhoneNumber(int code, String number)
    Adds a contact info entry for the phone number. Please, implement this method using an anonymous class. Use "Tel" for the entry title.
    addPhoneNumber(44, "444 444-44-44").getValue() will result to +44 444 444-44-44
  • addTwitter(String twitterId)
    Adds a contact info entry for the Twitter social media id. Use "Twitter" for the entry title, the given id for the value.
  • addInstagram(String instagramId)
    Adds a contact info entry for the Instagram social media id. Use "Instagram" for the entry title, the given id for the value.
  • addSocialMedia(String title, String id)
    Adds a contact info entry for the generic social media id. Use the given title for the entry title, the given id for the value.

Note that it is possible to rename contact with the rename method. Make sure it is not possible to rename contact to have null or empty value as the name.

One more method that the Contact class have is the getInfo() method. This method returns an array containing the ContactInfo entries in the following order:

  • name contact info
  • phone number contact info (if set)
  • email entries in order of addition (if any added)
  • social media entries in order of addition (if any added) Resulting array must not contain any null values.

Important restriction: Note that in this exercise you may not use Collections and Streams.

Examples

See usage examples in tests inside src/test/java.

contact-book's People

Contributors

yanovsk1y avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.