Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 408 Weeks Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Management Posted 07 Jul 2017 My Price 15.00

specification for a phone book

Problem 2

 

Here is the specification for a phone book. A phone book consists of a collection of entries. An entry associates a person’s name (a string) with a set of one or more phone contacts. Every entry in a phone book has a unique name. In the description below, we use ‘name entry’ to refer to the entry named by name.

A phone contact consists of a phone number and a label. (These are the PhoneContact objects from Assignment 3.) For any given entry, every contact has a unique label. We use ‘label contact’ to refer to the contact labeled by label within an entry. We can look up an entry in a phone book by name and, given an entry, we can look up a contact by label.

Here are a phone book’s principal methods:

add(name, phone_number, label)

If self (i.e., this phone book) has a name entry, then add to this entry a new label contact with phone_number if the entry has no labelcontact, else replace the phone number in its label contact by phone_number. If self does not have a name entry, add a new name entry with a label contact for phone_number.

find(name)

Return an array of the contacts in name entry if this entry exists in self; otherwise return nil.

find_contact(name, label)

Return the label contact under the name entry in self. If self has no name entry or its name entry has no label contact, return nil.

delete(name)

Delete the name entry from self. If self has no name entry, do nothing.

delete_contact(name, label)

Delete the label contact from the name entry from self. If this is the only contact under this entry, also delete the entry from self. If self has no such contact, do nothing.

to_s

Return a string representing all of the entries in self, sorted by name.

The behaviors assume all inputs are well-formed (e.g., name is a string, phone_number is wellformed based on PhoneNumber.new). Here’s a sample interaction:

book = PhoneBook.new

book.add('Lennon, John', '954-555-1234', 'work') book.add('Garcia, Jerry', 9541112222, 'work') book.add('Lennon, John', '(954) 123-4567', :home) book.add('Garcia, Jerry', 9541234567, 'cell') book.add('Simon, Paul', '9543334444', 'cell')

 

puts "**Entire book" puts book

puts "**Jerry's entry" puts book.find('Garcia, Jerry')

 

if not book.find('Jagger, Mick') thenputs "**No entry for Mick" end

puts "**Paul's cell number:"

puts book.find_contact('Simon, Paul', :cell)

 

book.add('Garcia, Jerry', '4445555555', :cell)

puts "**Jerry's new entry:" puts book.find('Garcia, Jerry')

 

puts "**Entire phone book:" puts book

puts "**Delete John's work number" book.delete_contact('Lennon, John', 'work')

puts book.find('Lennon, John')

 

puts "**Delete John's home number; should delete his entry"

book.delete_contact('Lennon, John', 'home') puts book.find('Lennon, John')

 

puts "**Delete Paul's entry" book.delete('Simon, Paul')

 

puts "**Now we have only Jerry's entry in the whole book" puts book

 

Here’s the output produced by the above program:

**Entire book Garcia, Jerry:

(954) 123-4567 (cell)

(954) 111-2222 (work)

Lennon, John:

(954) 123-4567 (home)

(954) 555-1234 (work)

Simon, Paul:

(954) 333-4444 (cell)

**Jerry's entry

(954) 111-2222 (work)

(954) 123-4567 (cell)

**No entry for Mick **Paul's cell number:

(954) 333-4444 (cell) **Jerry's new entry:

(954) 111-2222 (work)

(444) 555-5555 (cell) **Entire phone book: Garcia, Jerry:

(444) 555-5555 (cell)

(954) 111-2222 (work)

Lennon, John:

(954) 123-4567 (home)

(954) 555-1234 (work)

Simon, Paul:

(954) 333-4444 (cell)

**Delete John's work number

(954) 123-4567 (home)

**Delete John's home number; should delete his entry

 

**Delete Paul's entry

**Now we have only Jerry's entry in the whole book

Garcia, Jerry:

(444) 555-5555 (cell)

(954) 111-2222 (work)

a. Now we get to the assignment. Work on the design using scenario diagrams. Here are five scenarios, where we assume throughout that input is well-formed:

 

1.a_phone_book responds to a add(name, phone_number, label)message where it does not yet contain a name entry.

 

2.a_phone_book responds to a add(name, phone_number, label)message where it already contains a name entry and this entry does not contain a label contact.

 

3.a_phone_book responds to a find(name) message where it contains a name entry.

 

4.a_phone_book responds to a find_contact(name, label) message where it contains a name entry that contains a label contact.

 

5.a_phone_book responds to a delete_contact(name, label)where it contains a name entry whose sole contact is a label contact (i.e., the entry should be deleted from this phone book).

Draw a scenario diagram for each of these scenarios (five scenario diagrams in total).

 

b. Code the program in Ruby language.Problem 2 

 

Here is the specification for a phone book. A phone book consists of a collection of entries. An entry associates a person’s name (a string) with a set of one or more phone contacts. Every entry in a phone book has a unique name. In the description below, we use ‘name entry’ to refer to the entry named by name. 

A phone contact consists of a phone number and a label. (These are the PhoneContact objects from Assignment 3.) For any given entry, every contact has a unique label. We use ‘label contact’ to refer to the contact labeled by label within an entry. We can look up an entry in a phone book by name and, given an entry, we can look up a contact by label. 

Here are a phone book’s principal methods: 

add(name, phone_number, label) 

If self (i.e., this phone book) has a name entry, then add to this entry a new label contact with phone_number if the entry has no label contact, else replace the phone number in its label contact by phone_number. If self does not have a name entry, add a new name entry with a label contact for phone_number. 

find(name) 

Return an array of the contacts in name entry if this entry exists in self; otherwise return nil. 

find_contact(name, label) 

Return the label contact under the name entry in self. If self has no name entry or its name entry has no label contact, return nil. 

delete(name) 

Delete the name entry from self. If self has no name entry, do nothing. 

delete_contact(name, label) 

Delete the label contact from the name entry from self. If this is the only contact under this entry, also delete the entry from self. If self has no such contact, do nothing. 

to_s 

Return a string representing all of the entries in self, sorted by name. 

The behaviors assume all inputs are well-formed (e.g., name is a string, phone_number is wellformed based on PhoneNumber.new). Here’s a sample interaction: 

book = PhoneBook.new 

book.add('Lennon, John', '954-555-1234', 'work') book.add('Garcia, Jerry', 9541112222, 'work') book.add('Lennon, John', '(954) 123-4567', :home) book.add('Garcia, Jerry', 9541234567, 'cell') book.add('Simon, Paul', '9543334444', 'cell') 

 

puts "**Entire book" puts book  

puts "**Jerry's entry" puts book.find('Garcia, Jerry') 

 

if not book.find('Jagger, Mick') then     puts "**No entry for Mick" end  

puts "**Paul's cell number:" 

puts book.find_contact('Simon, Paul', :cell) 

 

book.add('Garcia, Jerry', '4445555555', :cell) 

puts "**Jerry's new entry:" puts book.find('Garcia, Jerry') 

 

puts "**Entire phone book:" puts book  

puts "**Delete John's work number" book.delete_contact('Lennon, John', 'work') 

puts book.find('Lennon, John') 

 

puts "**Delete John's home number; should delete his entry" 

book.delete_contact('Lennon, John', 'home') puts book.find('Lennon, John') 

 

puts "**Delete Paul's entry" book.delete('Simon, Paul') 

 

puts "**Now we have only Jerry's entry in the whole book" puts book 

 

Here’s the output produced by the above program: 

**Entire book Garcia, Jerry: 

        (954) 123-4567 (cell) 

        (954) 111-2222 (work) 

Lennon, John: 

        (954) 123-4567 (home) 

        (954) 555-1234 (work) 

Simon, Paul: 

        (954) 333-4444 (cell) 

**Jerry's entry 

(954) 111-2222 (work) 

(954) 123-4567 (cell) 

**No entry for Mick **Paul's cell number: 

(954) 333-4444 (cell) **Jerry's new entry: 

(954) 111-2222 (work) 

(444) 555-5555 (cell) **Entire phone book: Garcia, Jerry: 

        (444) 555-5555 (cell) 

        (954) 111-2222 (work) 

Lennon, John: 

        (954) 123-4567 (home) 

        (954) 555-1234 (work) 

Simon, Paul: 

        (954) 333-4444 (cell) 

**Delete John's work number 

(954) 123-4567 (home) 

**Delete John's home number; should delete his entry 

 

**Delete Paul's entry 

**Now we have only Jerry's entry in the whole book 

Garcia, Jerry: 

        (444) 555-5555 (cell) 

        (954) 111-2222 (work) 

a. Now we get to the assignment. Work on the design using scenario diagrams. Here are five scenarios, where we assume throughout that input is well-formed: 

 

a_phone_book responds to a add(name, phone_number, label) message where it does not yet contain a name entry. 

 

a_phone_book responds to a add(name, phone_number, label) message where it already contains a name entry and this entry does not contain a label contact. 

 

a_phone_book responds to a find(name) message where it contains a name entry. 

 

a_phone_book responds to a find_contact(name, label) message where it contains a name entry that contains a label contact. 

 

a_phone_book responds to a delete_contact(name, label) where it contains a name entry whose sole contact is a label contact (i.e., the entry should be deleted from this phone book). 

Draw a scenario diagram for each of these scenarios (five scenario diagrams in total). 

 

     b. Code the program in Ruby language.

Answers

(5)
Status NEW Posted 07 Jul 2017 07:07 PM My Price 15.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â-----------  -----------  -----------  ----------- T-----------han-----------k Y-----------ou -----------for----------- us-----------ing----------- ou-----------r w-----------ebs-----------ite----------- an-----------d a-----------cqu-----------isi-----------tio-----------n o-----------f m-----------y p-----------ost-----------ed -----------sol-----------uti-----------on.----------- Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m o-----------nli-----------ne -----------or -----------inb-----------ox -----------me -----------a m-----------ess-----------age-----------

Not Rated(0)