Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ruby Programming you will be implementing a PhoneBook class. It is up to you to decide how to store the data (i.e., how to define

Ruby Programming

you will be implementing a PhoneBook class. It is up to you to decide how to store the data (i.e., how to define a phonebook instance's fields) so that you can correctly implement all the required methods.

initialize

  • Description: This is the constructor. You should initialize the fields that you think your class needs for successful evaluation of the remaining methods. We do not test the constructor directly, but we do test it indirectly by testing the remaining methods.

add(name, number, is_listed)

  • Description: Adds a new entry to the PhoneBook. name is the name of the person and number is that person's phone number. The is\_listed parameter identifies if this entry should be listed or unlisted in the PhoneBook (true if listed, false if unlisted). Return true if the operation was successful, and false otherwise. Here are some cases to consider:
    • If the person already exists, then the entry cannot be added to the PhoneBook.
    • If number is not in the format NNN-NNN-NNNN, the entry cannot be added to the PhoneBook.
    • If number already exists and is listed in the PhoneBook, the entry cannot be added. However, if number exists and is unlisted, the entry can be added.
    • A number can be added as unlisted any number of times, but can only be added as listed once.
  • Type: (String, String, Bool) -> Bool
  • Assumptions: No phone number will start with 0.
  • Examples:
    @phonebook = PhoneBook.new @phonebook.add("John", "110-192-1862", false) == true @phonebook.add("Jane", "220-134-1312", false) == true @phonebook.add("John", "110-192-1862", false) == false @phonebook.add("Ravi", "110", true) == false

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions