import java.io.*;
import java.util.*;
/**
*This class provides a method that reads choice from the
*standard input. And it can displays the information of
*ICarnegie.
* @author WenLilong
* @version 1.0.0
*/
public class ICarnegieInfoApplication {
private static BufferedReader stdIn =
new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter stdOut =
new PrintWriter(System.out, true);
private static PrintWriter stdErr =
new PrintWriter(System.err, true);
/* DOCUMENT THIS PUBLIC METHOD */
/**
*This is the main idea.
* Attach the choice with each certain information.
* @param args not used
* @throws IOException if errors reading from standard input.
*/
public static void main(String[] args) throws IOException {
ICarnegieInfo companyInfo = ICarnegieInfo.getInstance();
int choice = getChoice();
while (choice != 0) {
if (choice == 1) {
stdOut.println(companyInfo.getName());
} else if (choice == 2) {
stdOut.println(companyInfo.getAddress());
} else if (choice == 3) {
stdOut.println(companyInfo.getTelephone());
} else if (choice == 4) {
stdOut.println(companyInfo.getEmail());
} else if (choice == 5) {
stdOut.println(companyInfo.getUrl());
}
choice = getChoice();
}
}
private static int getChoice() throws IOException {
do {
int input;
try {
stdErr.println();
stdErr.print("[0] Quit\n"
+ "[1] displays name\n"
+ "[2] displays address\n"
+ "[3] displays telephone\n"
+ "[4] displays email\n"
+ "[5] displays URL \n"
+ "choice>");
stdErr.flush();
input = Integer.parseInt(stdIn.readLine());
if (0 <= input && 5 >= input) {
return input;
} else {
stdErr.println("Invalid choice: " + input);
}
} catch (NumberFormatException nfe) {
stdErr.println(nfe);
}
} while (true);
/* PLACE YOUR CODE HERE */
//return 0; /* CHANGE THIS STATEMENT AS NEEDED */
}
}