zoukankan      html  css  js  c++  java
  • 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 */
        }

    }
  • 相关阅读:
    食物
    连在一起的幻想乡
    【XSY3209】RGB Sequence
    【Luogu4389】付公主的背包
    【BZOJ4555】【TJOI2016】【HEOI2016】求和
    【BZOJ3456】城市规划
    【BZOJ2693】jzptab & 【BZOJ2154】Crash的数字表格
    【Learning】左偏树
    小Z的袜子
    【BZOJ3625】【CF438E】小朋友和二叉树
  • 原文地址:https://www.cnblogs.com/vivizhyy/p/3394924.html
Copyright © 2011-2022 走看看