?? icarnegieinfoapplication.java
字號:
import java.io.*;
/**
* This class provides can get the information of Icarnegie
*
* @author Guiming Lin
* @version 1.0.1
*/
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);
/**
* ICarnegieInfoApplication presents the user with a menu of options,
* prompts the user for a choice, and processes the user's response
*
* @param args not used
* @throws IOException if error 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());
} else if (choice > 5) {
stdOut.println("Invalid choice: "+ choice);}
choice = getChoice();
}
}
/**
* Tests method <code>readInteger</code>
*
* @param args not used
* @throws IOException if error reading from standard input.
*/
private static int getChoice() throws IOException {
int number = 0;
do {
stdErr.println("[0] Quit");
stdErr.println("[1] Display name");
stdErr.println("[2] Display address");
stdErr.println("[3] Display telephone");
stdErr.println("[4] Display email");
stdErr.println("[5] Display URL");
stdErr.print("choice>");
stdErr.flush();
/*
* try to get the number from the standard input,
* and catch an exception if the user enters a choice that is not an integer
*/
try {
number = Integer.parseInt(stdIn.readLine());
}catch (NumberFormatException nfe) {
stdErr.println(nfe);
continue;
}
/*
* If the user enters an integer outside of the valid range [0,5],
* an error message is displayed.
*/
if(number>5||number<0){
stdErr.println("Invalid input");
continue;
}else{
return number;
}
} while (true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -