⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbooktextinterface.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
/** * Provide a textual interface to an AddressBook. * Different commands provide access to the data in the address book. * *      One to search the address book. * *      One to allow a set of contact details to be entered. * *      One to show all the entries in the book. * * @author David J. Barnes and Michael Kolling. * @version 2006.03.30 */public class AddressBookTextInterface{    // The address book to be viewed and manipulated.    private AddressBook book;    // A parser for handling user commands.    private Parser parser;        /**     * Constructor for objects of class AddressBookTextInterface     * @param book The address book to be manipulated.     */    public AddressBookTextInterface(AddressBook book)    {        this.book = book;        parser = new Parser();    }        /**     * Read a series of commands from the user to interact     * with the address book. Stop when the user types 'quit'.     */    public void run()    {        System.out.println("Address Book.");        System.out.println("Type 'help' for a list of commands.");                String command;        do{            command = parser.getCommand();            if(command.equals("add")){                 add();            }            else if(command.equals("get")){                get();            }            else if(command.equals("list")){                list();            }            else if(command.equals("search")){                find();            }            else if(command.equals("remove")){                remove();            }            else if(command.equals("help")){                help();            }            else{                // Do nothing.            }        } while(!(command.equals("quit")));        System.out.println("Goodbye.");    }        /**     * Add a new entry.     */    private void add()    {        System.out.print("Name: ");        String name = parser.readLine();        System.out.print("Phone: ");        String phone = parser.readLine();        System.out.print("Address: ");        String address = parser.readLine();        book.addDetails(new ContactDetails(name, phone, address));    }        /**     * Find an entry matching a key.     */    private void get()    {        System.out.println("Type the key of the entry.");        String key = parser.readLine();        ContactDetails result = book.getDetails(key);        System.out.println(result);    }        /**     * Remove an entry matching a key.     */    private void remove()    {        System.out.println("Type the key of the entry.");        String key = parser.readLine();        book.removeDetails(key);    }        /**     * Find entries matching a key prefix.     */    private void find()    {        System.out.println("Type a prefix of the key to be found.");        String prefix = parser.readLine();        ContactDetails[] results = book.search(prefix);        for(int i = 0; i < results.length; i++){            System.out.println(results[i]);            System.out.println("=====");        }    }        /**     * List the available commands.     */    private void help()    {        parser.showCommands();    }        /**     * List the address book's contents.     */    private void list()    {        System.out.println(book.listDetails());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -