/**
* ExceptionDemoApp.java
*
*
* Created: Sat Jan 11, 2003
*
* @author Stuart C. Shapiro
*
* Demonstrates the usefulness of Java assertions and exceptions.
*/
public class ExceptionDemoApp {
/**
* Prints n
, formatted as a 10-digit phone number,
* with the comment that it is a possible phone number.
*
* pre: n
.length == 10.
*
* post: n
is printed as a 10-digit phone number,
* formatted as a phone number,
* with the comment that it is a possible phone number.
*
* @param n a 10-digit String
.
*/
public static void CheckPhoneNumber (String n) {
if (n.length() != 10) {
throw new IllegalArgumentException("Illegal phone number");}
System.out.println(n.substring(0,3) + "-" + n.substring(3,6)
+ "-" + n.substring(6)
+ " is a possible phone number.");
}
/**
* Driver for ExceptionDemoApp,
* demonstrating an exception.
*
*/
public static void main (String[] args) {
CheckPhoneNumber("7165551234");
CheckPhoneNumber("201467");
} // end of main ()
}// ExceptionDemoApp