Question: This application displays customer information for customers selected by the user. The application prompts the user to enter a customer number. If a customer with

This application displays customer information for customers selected by the user. The application prompts the user to enter a customer number. If a customer with that number exists, the application displays the customers name and address. If no customer with that number exists, the application displays the message The customer numberdoes not exist. Either way, the application then asks if the user wants to display another customer.

Specifications

Create a class named Customer that stores name, address,city, state, and zip-Code as public fields. The class should have a method named get-NameAndAddressthat returns the name and address information formatted as shown in the console output above.

To get the information for a customer, use the CustomerIO classthats provided. This class contains a method named getCustomerthat accepts a customer num-ber (an int value) and returns a Customer object.

Modify the getCustomermethod so that if its called with an invalid customer number, it throws an exception of type NoSuchCustomerException.

Create a NoSuchCustomerException class. This class should have a constructor that accepts an int parameter that provides the customer number that doesnt exist. This constructor should pass the message The customer number does not ex-ist. to the constructor of the Exception class.

The NoSuchCustomerException should store the customer number as a private in-stance variable and make it available through a method named getCustomer-Number.

Create a CustomerApp class. If the user enters an invalid customer number, thismain application class should use the getCustomerNumbermethod to retrieve the customer number from the exception object when it displays the error message to the user.Enhancements(this part is not required and will not be counted for any extra credit)

Provide a constructor for the Customer class that accepts a customer number as a parameter and then attempts to create a Customer object using the data for that customer. Then, handle NoSuchCustomerException in the constructor of the Cus-tomer class. The constructor should throw the NoSuchCustomerException if an in-valid customer number is passed to it.

Same as the first enhancement, but have the constructor throw a different excep-tion named CouldNotCreateCustomerException if it cant create the customer. Then, it should chain the original NoSuchCustomerException in the CouldNotCre-ateCustomerException.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!