telephone.java

来自「这个是学习网络编程的好好文档! 里面有一些老师发给的学习jsp的课件!」· Java 代码 · 共 55 行

JAVA
55
字号
import java.io.BufferedReader;
import java.io.IOException;

/**
   A telephone that takes simulated keystrokes and voice input
   from the user and simulates spoken text.
*/
public class Telephone
{
   /**
      Construct phone object.
      @param aReader that reads text from a character-input stream
   */
   public Telephone(BufferedReader aReader)
   {
      reader = aReader;
   }

   /**
      Speak a message to System.out.
      @param output the text that will be "spoken"
   */
   public void speak(String output)
   {
      System.out.println(output);
   }

   /**
      Loops reading user input and passes the input to the 
      Connection object's methods dial, record or hangup.
      @param c the connection that connects this phone to the 
      voice mail system
   */
   public void run(Connection c) throws IOException
   {
      boolean more = true;
      while (more)
      {
         String input = reader.readLine();
         if (input == null) return;
         if (input.equalsIgnoreCase("H"))
            c.hangup();
         else if (input.equalsIgnoreCase("Q"))
            more = false;
         else if (input.length() == 1 
            && "1234567890#".indexOf(input) >= 0)
            c.dial(input);
         else            
            c.record(input);
      }
   }

   private BufferedReader reader;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?