CSC1110 - Week 5 Homework

Instructions

Create class called PhoneBook that has a single private String attribute called phoneNumber that stores a phone number. This class should have as setter for the phone number as well as the methods listed below.

Create a driver called PhoneBookDriver that creates an instance of a PhoneBook called pb, and asks the user for a phone number in the form of cc-area-local or ‘q’ to quit. Get the input from the user and use it to set the phone number of the PhoneBook object you created. You can assume the phone number entered by the user is a valid phone number. Use the methods of the PhoneBook object to print out the country code, area code, and local number of the phone number. Repeat the prompt, each time setting the new phone number entered by the user, until the user enter 'q'. If the user entered ‘q’ the program should end and print “Quitting”. Do not use break, System.exit(), or return to terminate a loop.

Sample Output

Enter a phone number in the form cc-area-local,
where cc = country code digits, area = area code digits,
and local = local phone digits.
Or enter q to quit:
1-816-7412000
country code = 1
area code = 816
local number = 7412000

Enter a phone number in the form cc-area-local,
where cc = country code digits, area = area code digits,
and local = local phone digits.
Or enter q to quit:
86-131-12345678
country code = 86
area code = 131
local number = 12345678

Enter a phone number in the form cc-area-local,
where cc = country code digits, area = area code digits,
and local = local phone digits.
Or enter q to quit:
1234567-89-0
country code = 1234567
area code = 89
local number = 0

Enter a phone number in the form cc-area-local,
where cc = country code digits, area = area code digits,
and local = local phone digits.
Or enter q to quit:
1-2-3
country code = 1
area code = 2
local number = 3

Enter a phone number in the form cc-area-local,
where cc = country code digits, area = area code digits,
and local = local phone digits.
Or enter q to quit:
q

Submission

See your professor's instructions for details on submission guidelines and due dates.