Write a class TelephoneNumber that will hold a telephone number. An object of this class will have the attributes
- areaCode—a three-digit integer
- exchangeCode—a three-digit integer
- number—a four-digit integer
and the methods
- TelephoneNumber (aString)—a constructor that creates and returns a new instance of its class, given a string in the form xxx–xxx–xxxx or, if the area code is missing, xxx–xxxx. Throw an exception if the format is not valid. (Hint: To simplify the constructor, you can replace each hyphen in the telephone number with a blank. To accept a telephone number containing hyphens, you could process the string one character at a time or learn how to use Scanner to read words separated by a character—such as a hyphen—other than whitespace.)
- toString—returns a string in either of the two formats shown previously for the constructor.
Using a text editor, create a text file of several telephone numbers, using the two formats described previously. Write a program that reads this file, displays the data on the screen, and creates an array whose base type is TelephoneNumber. Allow the user to either add or delete one telephone number. Write the modified data on the text file, replacing its original contents. Then read and display the numbers in the modified file.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Starting out with Visual C# (4th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
- Design a class named MyInteger. The class contains:■■ An int data field named value that stores the int value represented bythis object.■■ A constructor that creates a MyInteger object for the specified int value.■■ A getter method that returns the int value.■■ The methods isEven(), isOdd(), and isPrime() that return true if thevalue in this object is even, odd, or prime, respectively.■■ The static methods isEven(int), isOdd(int), and isPrime(int) thatreturn true if the specified value is even, odd, or prime, respectively.■■ The static methods isEven(MyInteger), isOdd(MyInteger), andisPrime(MyInteger) that return true if the specified value is even, odd,or prime, respectively.■■ The methods equals(int) and equals(MyInteger) that return true ifthe value in this object is equal to the specified value.■■ A static method parseInt(char[]) that converts an array of numericcharactersto an int value.■■ A static method parseInt(String) that converts a string into an int value.Draw the UML…arrow_forwardDefine a class in java representing physical elements (like hydrogen, helium, lithium,etc.). Elements have a name, a symbol, an integer atomic number, and an atomicweight (which may be fractional). Your class should have a constructor that setsall the properties, and a toString method that prints each element as a nicelyformatted String. Write accessors and mutators for each field if you think it isappropriate to do so (ask yourself if the field should be changeable). Update yourmain method to create and print 10 unique elements.arrow_forwardWrite the source code of the class Passenger. A passenger can travel with an infant (i.e. his/her child). Code the class Infant as an inner class of the class Passenger. If a passenger is not travelling with an infant, the getInfantMonths method must return –1.arrow_forward
- Write the Circle class:• A Circle has a radius– Add instance variable– 2 constructors – one should be the default or no args– Add accessor and mutator method for each instance variable– Add methods to calculate Area, Perimeter, and Diameter– Write a printArea method in the main program which receives an object circleand “times” integer– printArea() will print the radius and area of objects “times” time by changingthe radius of object.public static void printAreas(Circle c, int times) {System.out.println("Radius \t\t Area");while (times>=1) {//print the radius and area here// create a new object by changing the radius heretimes--;}}//end of printAreasarrow_forwardIn Python, #Create a basket class, which has a class/static attribute pricelist (string/float dictionary - you can hardcode this) #The constructor should set the name to the name passed as a parameter and initialise the contents (empty) #You should provide an addItem method taking product,quantity which adds this to the contents #and a getQuantity method taking a product, which returns the relevant quantityarrow_forwardCreate a class Rectangle with length and breadth as private data members and also provide the following member functions: getdata(): gets the length and breadth of rectangle. calarea(): return the area of the rectangle. calperi(): return the perimeter of the rectangle. issquare(): return true if the rectangle is squarearrow_forward
- suppose there is a class Alarm. Alarm has two class variables, code which contains a String value representing the code that deactivates the alarm, and armed with contains a boolean describing whether or not the alarm is activated. Alarm has a function disarm that changes the value of armed to False if the user gives a parameter containing the string that represents the alarm's code. Call the disarm function on the Alarm object myAlarm and give it the code "93478". using pythonarrow_forwardjavascript Need help defining a function frequencyAnalysis that accepts a string of lower-case letters as a parameter. frequencyAnalysis should return an object containing the amount of times each letter appeared in the string. example frequencyAnalysis('abca'); // => {a: 2, b: 1, c: 1}arrow_forwardCreate a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal (String name) //constructor public void makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don't make sounds!) Note, you'll also need a constructor in each of your subclasses which calls super(name) to initialize the common 'name' member of Animal. Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. (you should observe the makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…arrow_forward
- Create a class BeautyProduct with name, color, brand. Provide Constructors, getters, setters and also write toString method. Now create a class Lipstick which extends the class BeautyProduct as Lipstick is-a Beauty Product it has totalVolume, remainingVolume, price, texture (gloss, matt) as private data members. Provide Constructors, getters, setters and an apply() method whenever this method is called a beauty item is applied and its volume decreases by 10.This should also check that volume must not be zero if it then u have to throw exception. Also write toString method which prints all details like name, color, brand, price, texture and volume. Create another class foundation having totalVolume, remainingVolume, price, texture (liquid, cake) and lastingTime (number of hours foundation remain intact on face and does not crease) as private data members. This also extends the base class i.e. BeautyProduct. Provide Constructors, getters, setters and an apply() method whenever this…arrow_forwardWrite a class definition line and a one line docstring for the class Dog. Write an __init__ method for the class Dog that gives each dog its own name and breed. Test this on a successful creation of a Dog object.>>> import dog>>> sugar = dog.Dog('Sugar', 'border collie')>>> sugar.name'Sugar'>>> sugar.breed'border collie' Add a data attribute tricks of type list to each Dog instance and initialize it in __init__ to the empty list. The user does not have to supply a list of tricks when constructing a Dog instance. Make sure that you test this successfully.>>> sugar.tricks[] Write a method teach as part of the class Dog. The method teach should add a passed string parameter to tricks and print a message that the dog knows the trick.>>> sugar.teach('frisbee')Sugar knows frisbeearrow_forwardCreate a class MyTime which has the datamembers as follows: 1. hour: integer (1 to 12)2. minute: integer (0 to 59)3. second: integer (0 to 59)4. pm: bool variable. True means PM time and false means AM time. Implement a default constructor, a parameterized constructor and a copy constructor. Write set and get functions for all the four members of the class. Overload these operators: 1. Extraction operator >> : Prompt the user for hours, minutes, seconds and for am/pm and initialize the structure. Left operand istream object and right operand MyTime2. Assignment = : Assign the right object to the left object. Both operands are of type MyTime.3. Insertion << : Print the time in the format HH:MM SS PM. Left operand of type ostream and right operand of type MyTime. this in c++.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,