📄 practical quiz 1.icarnegieinfoapplication.java
字号:
import java.io.*;
import java.util.*;
/**
* This is a application for getting information about <cite>iCarnegie</cite>
*
* @author Neil
* @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);
/**
* Presents the user with a menu of options and
* verifies the user's choice.
*
* @param args not used
*/
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{
stdOut.println("[0] Quit");
stdOut.println("[1] Display name");
stdOut.println("[2] Display address");
stdOut.println("[3] Display telephone");
stdOut.println("[4] Display email");
stdOut.println("[5] Display URL");
stdOut.print("choice>");
stdOut.flush();
try {
int value = Integer.parseInt(stdIn.readLine());
if (value>5 || value<0){
stdErr.println("Invalid choice: " + value);
}
else{
return value;
}
} catch (NumberFormatException nfe) {
stdOut.println(nfe);
}
} while (true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -