import java.util.Scanner; public class CustomerApp { public static void main(String args[]) { PriceHeading.getHeading("Assignment 3");//heading call // display a welcome message System.out.println(" Welcome to the Customer application"); System.out.println(); // create the Scanner object Scanner sc = new Scanner(System.in); // continue until user enters x String custNo = "y"; while (!custNo.equalsIgnoreCase("x")) { custNo = Validator.getString(sc, " Enter a customer number (or an \"X\" to quit) -> "); //gets customers name and address try { Customer cust = CustomerIO.getCustomer(custNo); System.out.println("\n" + cust.getNameAndAddress()); } catch (NoSuchCustomerException e){ System.out.println(e.getMessage()); } } System.out.println(); } }
class NoSuchCustomerException extends Exception { private String customerNumber; public NoSuchCustomerException() { } public NoSuchCustomerException(String customerNumber){ super(" The customer number " + customerNumber.toUpperCase() + " does not exist"); } public String getCustomerNumber(){ return customerNumber; } }