• SSD 3 Practical Quiz 1 答案


    import java.io.*;
    import java.util.*;

    /**
     * @version 1.0.0
     * @author vivizhyy
     */
    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);
        private int choice;

        /* DOCUMENT THIS PUBLIC METHOD */
        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 {
            int input = 0;
            /* PLACE YOUR CODE HERE */

            try {
                stdErr
                        .print("[0] Quit/n[1] Display name/n[2] Display address"
                                + "/n[3] Display telephone/n[4] Display email/n[5] Display URL"
                                + "/nchoice>");
                stdErr.flush();
                input = Integer.parseInt(stdIn.readLine());
                if (input < 0 || input > 5) {
                    System.out.println("Invalid choice: " + input);
                }
            } catch (NumberFormatException nfe) {
                 nfe.printStackTrace();//写一大段
                // System.out.println(nfe.getMessage()); the output result
                // was just "For input string "aa""
                // System.out.println(nfe.getCause()); output "null"
                // System.out.println(nfe.getLocalizedMessage()); the same as
                // .getMessage
                //stdErr.println(nfe.getMessage());// the same as .getMessage
                input=getChoice();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            return input; /* CHANGE THIS STATEMENT AS NEEDED */
        }

    }
  • 相关阅读:
    用python写爬虫
    ASM上的备份集如何转移到文件系统中
    Web基础知识和技术
    java调用存储过程超时及DBCP参数配置说明
    android JNI--- 搭建环境(1)
    android jni——helloworld
    程序设计的预防与诊断
    [置顶] 某大型银行深化系统技术方案之十七:技术架构
    Ubuntu12.04 Eclipse 提示框背景色修改
    window与linux互相拷贝文件
  • 原文地址:https://www.cnblogs.com/vivizhyy/p/3394924.html
Copyright © 2020-2023  润新知