Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java language Using the Name class of Lab 3.1 as a guide, code a PhoneNumber class and its associated main. The class should have

In Java language

Using the Name class of Lab 3.1 as a guide, code a PhoneNumber class and its associated main. The class should have the following state:

  • A single string, number

and the following behavior:

  • a constructor that accepts a string representing the phone number (you can assume until informed otherwise that the phone number is always in the proper format of (nnn)nnn-nnnn.
  • methods getAreaCode, getExchange, and getLineNumber that return the first three digits, the moddle three digits, and the last four digits respec. of the number
  • a method, isFreeToll that returns true if the number is a toll-free phone number (i.e., the area code begins with an '8').
  • toString, equals, and read methods that correspond to their counterparts in the Name class.
  • A main method that performs similar logic to that of the Name class, i.e.,
    • opens the file numbers.text
    • reads in PhoneNumber objects, using the read method of the class (until null is returned).
    • prints out the PhoneNUmber object (using toString)
    • prints out whether the number is toll free
    • checks for adjacent duplicate numbers
    • keeps count of the number of PhoneNumbers read in

The name of your class should be PhoneNumber. Please remove the public attribute from your class definition (CodeLab restriction).

For example, if the file numbers.text contains:

(356)153-9460 (290)261-7625 (761)321-9457 (724)091-7819 (759)301-3133 (072)023-0203 (060)075-3782 (060)075-3782 (369)348-9660 (844)824-5853 (692)839-8466 (216)386-2922 

the program should produce the following output:

phone number: (356)153-9460 area code: 356 exchange: 153 line number: 9460 is free toll: false phone number: (290)261-7625 area code: 290 exchange: 261 line number: 7625 is free toll: false phone number: (761)321-9457 area code: 761 exchange: 321 line number: 9457 is free toll: false phone number: (724)091-7819 area code: 724 exchange: 091 line number: 7819 is free toll: false phone number: (759)301-3133 area code: 759 exchange: 301 line number: 3133 is free toll: false phone number: (072)023-0203 area code: 072 exchange: 023 line number: 0203 is free toll: false phone number: (060)075-3782 area code: 060 exchange: 075 line number: 3782 is free toll: false Duplicate phone number "(060)075-3782" discovered phone number: (369)348-9660 area code: 369 exchange: 348 line number: 9660 is free toll: false phone number: (844)824-5853 area code: 844 exchange: 824 line number: 5853 is free toll: true phone number: (692)839-8466 area code: 692 exchange: 839 line number: 8466 is free toll: false phone number: (216)386-2922 area code: 216 exchange: 386 line number: 2922 is free toll: false --- 12 phone numbers processed. 

Instructor Notes:

Include a copy constructor in this class as well.

I need help with printing

Duplicate phone number "(060)075-3782" discovered in the output.

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

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions