GithubHelp home page GithubHelp logo

zcw-microlabs-exceptionsandlogging's Introduction

ZCW-MicroLabs-ExceptionsAndLogging

PhoneNumberFactory

  • Purpose - to demonstrate basic exception handling and logging.

  • Objective - to implement a PhoneNumberFactory class that generates PhoneNumber objects.

  • The PhoneNumber class is a container for a String representation of a respective phone number.

  • Note: Phone numbers are a composite of 3 affixes; Area Code, Central Office Code, and Phone Line Code.

    • Area Code - the first 3 numeric values
    • Central Office Code - the 4th, 5th, and 6th numeric values.
    • Phone Line Code - the last 4 numeric values.
  • Below is a sample instantation of and invokation on PhoneNumber.

String stringRepresentation = "(302)-312-5555)";
PhoneNumber phoneNumber = new PhoneNumber(stringRepresentation);
String areaCode = phoneNumber.getAreaCode();
String centralOfficeCode = phoneNumber.getCentralOfficeCode();
String phoneLineCode = phoneNumber.getPhoneLineCode();

Part 1; Modify createPhoneNumber

  • Upon instantiating a new PhoneNumber object, it is possible to receive a InvalidPhoneNumberFormatException if the String passed into the PhoneNumber constructor does not fit the format (###)-###-####.
  • InvalidPhoneNumberFormatException extends IOException, which is a checked exception.
  • Modify the createPhoneNumber method so that it throws any resulting InvalidPhoneNumberFormatException.
    • This will ensure that any method calling createPhoneNumber will have to handle the exception.

Part 2; Implement createPhoneNumberSafely

  • Using the createPhoneNumber method from Part 1, define the createPhoneNumberSafely method such that the input parameters, areaCode, centralOfficeCode, phoneLineCode are concatenated to create a String representation of the respective phone number.
  • Use this String object to construct a new instance of PhoneNumber and return it.
  • If the concatentation of the input parameters yields a String whose value does not match the format (###)-###-####, then our PhoneNumber will throw a InvalidPhoneNumberFormatException.
  • If a InvalidPhoneNumberFormatException is thrown within this method, catch it and return null.

Part 3; Implement createRandomPhoneNumber

  • Using the RandomNumberFactory, generate a random Area Code, Central Office Code, and Phone Line Code. Pass these values as arguments of the createPhoneNumberSafely method from Part 2 and return the resulting PhoneNumber object.

Part 4; Implement createRandomPhoneNumberArray

  • Using the createRandomPhoneNumber from Part 3, generate an array of PhoneNumber objects, whose length reflects the input argument.
    • For example createRandomPhoneNumber(5) should return an array of 5 PhoneNumber objects.

Part 5; Add logging

  • Add logging to the createPhoneNumber method from Part 1, which logs the message

    • "Attempting to create a new PhoneNumber object with a value of (###)-###-####
    • where (###)-###-#### will be replaced with the respective input parameter.
  • Add logging to the createPhoneNumberSafely method from Part 2, which logs the message

    • (###)-###-#### is not a valid phone number
    • Where (###)-###-#### will be replaced with the respective input parameter.

Part 6; Ensure all test cases pass

  • Yeah this header says all that is needed...

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.