// ************************************************************************
// FoneFun is a program that takes the input from the command prompt and  
// creates a StringTokenizer object from the input, and then passes that object to  
// three different methods, one by by, to return the appropriate token. Note that if 
// the string entered goes beyond the three-digit-series of a phonenumber, 
// the elements will get parsed anyway. In other words, no error checking or
// length checking, and the while() loop will ensure that repeated tokens get
// processed, regardless of length.
// 
// Kelli Wiseth
// 9-August-2004
// Platform: 	Wintel [Windows 2000]
// JDK version:	JDK 1.4.1
// Time spent: ~ 4 hours
//******************************************************************************

import java.io.*;
import java.util.StringTokenizer;


class FoneFun

   {

//****************************************************************************
// The main method functions as the driver for the program. It prompts the user 
// to enter a telephone number, and then calls three different
// methods, passing the StringTokenizer object to each method. Each method 
// in turn returns just the nextToken of the object. There's no error
// checking in this program. 
//**************************************************************************** 
    

  public static void main (String args[]) throws IOException
    {

    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter a phone number in the format nnn-nnn-nnnn:    ");
    System.out.flush();

    String fonenumber=stdin.readLine();
    StringTokenizer fone_set= new StringTokenizer (fonenumber, "-");
    while (fone_set.hasMoreTokens())
      {
       System.out.println("\n\n  " + getAreaCode(fone_set) + " is the area code");
       System.out.println("  " + getExchange(fone_set) + " is the exchange");
       System.out.println("  " + getExtension(fone_set) + " is the extension");
      }
   
    }//main method closing brace

//*************************************************************************   
// The "getAreaCode" method accepts the StringTokenizer object (fone_set)  
// from main and returns the first token.
// 
//*************************************************************************
     static String getAreaCode(StringTokenizer input)
     {
     
     String area=input.nextToken();
     return area;
 
     } // Method "getAreaCode" closing brace


//*************************************************************************   
// The "getExchange" method accepts the StringTokenizer object from main  
// and returns the nextToken (in this case, the second token).
// 
//*************************************************************************
     static String getExchange(StringTokenizer input)
     {
     
     String exchange=input.nextToken();
     return exchange;
 
     } // Method "getExchange" closing brace


//*************************************************************************   
// The "getExtension" method accepts the StringTokenizer object from main  
// and returns the nextToken (in this case, the last token). 
// 
//*************************************************************************
     static String getExtension(StringTokenizer input)
     {
     
     String extension=input.nextToken();
     return extension;
 
     } // Method "getExtension" closing brace


}//class FoneFun closing brace
