1 import java.util.Scanner;
2
3 /**
4
5
6 */
7 public class Telephone
8 {
9 /**
10
11 @param aScanner
12 */
13 public Telephone(Scanner aScanner)
14 {
15 scanner = aScanner;
16 }
17
18 /**
19
20 @param output
21 */
22 public void speak(String output)
23 {
24 System.out.println(output);
25 }
26
27 /**
28
29
30 @param c
31
32 */
33 public void run(Connection c)
34 {
35 boolean more = true;
36 while (more)
37 {
38 String input = scanner.nextLine();
39 if (input == null) return;
40 if (input.equalsIgnoreCase("H"))
41 c.hangup();
42 else if (input.equalsIgnoreCase("Q"))
43 more = false;
44 else if (input.length() == 1
45 && "1234567890#".contains(input))
46 c.dial(input);
47 else
48 c.record(input);
49 }
50 }
51
52 private Scanner scanner;
53 }