CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Assignment #12

Display customer information

Due Date: Monday of Week 5
30 points

This project requires a custom exception that's thrown if the customer the user requests isn't found. A CustomerIO class that contains a method that simulates retrieving a customer is provided. This is a manageable project for working with custom exceptions.

Console

Operation

  • 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 customer's name and address. If no customer with that number exists, the application displays the message "The customer number does 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 zipCode as public fields. The class should have a method named getNameAndAddress that returns the name and address information formatted as shown in the console output above.
  • To get the information for a customer, use the CustomerIO class that's provided. This class contains a method named getCustomer that accepts a customer number (an int value) and returns a Customer object.
  • Modify the getCustomer method so that if it's 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 doesn't exist. This constructor should pass the message "The customer number does not exist." To the constructor of the Exception class.
  • The NoSuchCustomerException should store the customer number as a private instance variable and make it available through a method named getCustomerNumber. If the user enters an invalid customer number, the main application class should use the getCustomerNumber method to retrieve the customer number from the exception object when it displays the error message to the user.

Enhancements

  • 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 Customer class. The constructor should throw the NoSuchCustomerException if an invalid customer number is passed to it.
  • Same as the first enhancement, but have the constructor throw a different exception named CouldNotCreateCustomerException if it can't create the customer. Then, it should chain the original NoSuchCustomerException in the CouldNotCreateCustomerException.
  • Enhance the getCustomer method so that it also throws IOException. To simulate the random nature of IOExceptions, have your students code the class so that IOException is thrown randomly, with a 10% chance of the exception being thrown.
Include in your program the following comments:
  • Name of program
  • Programmer's name
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

When you are ready, upload the java program by clicking the link below:

Upload Assignment

I cannot grade if I don't get the files and receive your email.