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
- write program in java Design an abstract class GeometricObject. GeometricObject must ensure that its children must implement calcArea() method. Design RectangleYourRegNo and CircleYourName Classes as children of GeometricObject class with overridden toString() method to return “Rectangle with w Width and h Height is drawn” OR “Circle with r Radius is drawn”. The attributes of Rectangle are length, width. The attribute of Circle is radius Hint: Area of circle=πr2 , Area of rectangle= width*lengtharrow_forwardWe have a parking office class for an object-oriented parking management system using java Add(implement) a method to the Parking Office class to return the collection of permit ids for a specific customer (getPermitIds(Customer)) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getPermitIds(Customer) method as mentioned above Explain your code in a few words Important- We have a method to return a collection of permit ids (getPermitIds), what we need is a method to return the collection of permit ids for a specific customer (getPermitIds(Customer))arrow_forward1) Implement a class Moth that models a moth flying along a straight line. The moth hasa position, which is the distance from a fixed origin. When the moth moves toward apoint of light, its new position is halfway between its old position and the position ofthe light source. Find the instance variable(s), define and implement the constructor(s), then supplythe following methods:- public void moveToLight(double lightPosition) - public double getPosition()2) Document your class, generate Javadoc documentation and produce a test program ‘MothTester’that construct a moth, move it toward a couple of light sources, and check that the moth’s positionis as expected. 3) Add a comment to your class Moth that explains how you can make the Moth immobile after 10moves.arrow_forward
- 1) Implement a class Moth that models a moth flying along a straight line. The moth hasa position, which is the distance from a fixed origin. When the moth moves toward apoint of light, its new position is halfway between its old position and the position ofthe light source. Find the instance variable(s), define and implement the constructor(s), then supplythe following methods:- public void moveToLight(double lightPosition)- public double getPosition()2) Document your class, generate Javadoc documentation and produce a test program ‘MothTester’that construct a moth, move it toward a couple of light sources, and check that the moth’s positionis as expected.3) Add a comment to your class Moth that explains how you can make the Moth immobile after 10moves.arrow_forwardModify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger of two GeometricObject objects. Draw the UML diagram and implement the new GeometricObject class. Write a test program that uses the max method to find the larger of two circles, the larger of two rectangles.using java programmingarrow_forwardWe have a parking office class for an object-oriented parking management system using java Add (implement )a method to the Parking Office c to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class defination like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID method as mentioned abovearrow_forward
- Define 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_forwardCreate a parent class Person with one attribute age and one method greet() that prints out "Hello, world!". By default, the age is 20. Then create a subclass CollegeStudent that inherits from Person and has its own attributes School_Name and Major. Then create an object (a college student, his name is Harry, age is 21, School_Name is "Felician University", and Major is "Computer Science"), then let Harry say"Hello World!".arrow_forwardImplement a class Moth that models a moth flying along a straight line. The moth hasa position, which is the distance from a fixed origin. When the moth moves toward apoint of light, its new position is halfway between its old position and the position ofthe light source. Find the instance variable(s), define and implement the constructor(s), then supplythe following methods:- public void moveToLight(double lightPosition)- public double getPosition() Document your class, generate Javadoc documentation and produce a test program ‘MothTester’that construct a moth, move it toward a couple of light sources, and check that the moth’s positionis as expected. Add a comment to your class Moth that explains how you can make the Moth immobile after 10moves.arrow_forward
- Given the main class Dog, subclass Poodle, and the beginning of the subclass Pug:Instructions for Pug.java Variables: int flabCount – the count of layers on the Pug An invalid value should default this field to 25. A value is invalid if it is nonpositive. boolean isPound – whether this Pug resides in the pound. Poodle bestFriend- a Poodle who is the best friend with the Pug Constructors: A constructor that takes in name, length, weight, stripeCount, isSaltwater, and bestFriend. The bestFriend argument should be deep copied. A constructor that takes in no parameters and sets name to “Pluto”, length to 30.0, weight to 320.0, stripeCount to 14, isPound to false, and bestFriend to null. A copy constructor that deep copies all necessary instance fields. Methods: migrate The pug moves to the opposite kind of living situation if and only if it does not have a best friend. For example, if this pug were now in a pound and it has a best friend, it would not migrate to a…arrow_forwardWe have a parking office class for an object-oriented parking management system using java Add (implement) a method to the Parking Office to return a collection of permit ids (getPermitIds) I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....). N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getPermitIds method as mentioned above Explain your code in a few wordsarrow_forwardProvide a method that swaps the values with the smallest and largest measure in an array of objects of a class that implements the Measurable interface. ** A bank account has a balance that can be changed by deposits and withdrawals.*/public class BankAccount implements Measurable{ private double balance; /** Constructs a bank account with a zero balance. */ public BankAccount() { balance = 0; } /** Constructs a bank account with a given balance. @param initialBalance the initial balance */ public BankAccount(double initialBalance) { balance = initialBalance; } /** Deposits money into the bank account. @param amount the amount to deposit */ public void deposit(double amount) { balance = balance + amount; } /** Withdraws money from the bank account. @param amount the amount to withdraw */ public void withdraw(double amount) { balance = balance - amount; } /**…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education