当前位置: 代码迷 >> Java相关 >> 这个看不懂 能否帮我注解一下
  详细解决方案

这个看不懂 能否帮我注解一下

热度:137   发布时间:2009-10-21 11:06:37.0
这个看不懂 能否帮我注解一下
// Level 3 lab
package bank;
public class Teller {
    Account myAccount;
    public static void main (String args[]) {
    Teller me = new Teller();
    me.menu();
    }
    public Teller() {
    try {
        int count;
        byte inData[] = new byte[40];
        String inName;
        Double inMoney;
        System.out.print("Enter account name: ");
        count = System.in.read(inData);
        if (count == -1) {
        System.err.println("Error reading account name");
        System.exit(1);
        }
        inName = new String(inData,0,count-1);
        System.out.print("Enter amount to open account: ");
        count = System.in.read(inData);
        if (count == -1) {
        System.err.println("Error reading amount");
        System.exit(1);
        }
        inMoney = Double.valueOf(new String(inData,0,count-1));
        myAccount = new Account(inName,inMoney.doubleValue());
    } catch (Exception e) {
        System.err.println("Exception thrown:"+e.toString());
        System.exit(1);
    }
    }
    public void menu() {
    try {
        int key;
        byte inData[] = new byte[40];
        Double money;
        while(true) {
        System.out.print("(B)alance (D)eposit (W)ithdraw (Q)uit: ");
        key = System.in.read(inData);
        if (key == -1 ||
            (char)inData[0] == 'q' || (char)inData[0] == 'Q') {
            myAccount.print();
            System.exit(0);
        }
        if ((char)inData[0] == 'b' || (char)inData[0] == 'B') {
            myAccount.print();
        }
        if ((char)inData[0] == 'd' || (char)inData[0] == 'D') {
            System.out.print("Enter amount of deposit: ");
            key = System.in.read(inData);
            if (key != -1) {
            money = Double.valueOf(new String(inData,0,key-1));
            if (myAccount.deposit(money.doubleValue()) == 0) {
                System.out.println("Deposit has been made");
            } else {
                System.out.println("Problem with Deposit");
            }
            }
        }
        if ((char)inData[0] == 'w' || (char)inData[0] == 'W') {
            System.out.print("Enter amount of withdraw: ");
            key = System.in.read(inData);
            if (key != -1) {
            money = Double.valueOf(new String(inData,0,key-1));
            if (myAccount.withdraw(money.doubleValue()) == 0) {
                System.out.println("Withdraw has been made");
            } else {
                System.out.println("Problem with Withdraw");
            }
            }
        }
        }
    } catch (Exception e) {
        System.err.println("Exception thrown");
        System.exit(1);
    }
    }
}
搜索更多相关的解决方案: 注解  

----------------解决方案--------------------------------------------------------
从键盘输入相宜的选项(("(B)alance (D)eposit (W)ithdraw (Q)uit:)
程序进行判断,分别对不同的选项调用不同的功能。
----------------解决方案--------------------------------------------------------
哦 谢谢 还能给我解释下 这段代码吗?
public void menu() {
    try {
        int key;
        byte inData[] = new byte[40];
        Double money;
        while(true) {
        System.out.print("(B)alance (D)eposit (W)ithdraw (Q)uit: ");
        key = System.in.read(inData);
        if (key == -1 ||
            (char)inData[0] == 'q' || (char)inData[0] == 'Q') {
            myAccount.print();
            System.exit(0);
        }
        if ((char)inData[0] == 'b' || (char)inData[0] == 'B') {
            myAccount.print();
        }
        if ((char)inData[0] == 'd' || (char)inData[0] == 'D') {
            System.out.print("Enter amount of deposit: ");
            key = System.in.read(inData);
            if (key != -1) {
            money = Double.valueOf(new String(inData,0,key-1));
            if (myAccount.deposit(money.doubleValue()) == 0) {
                System.out.println("Deposit has been made");
            } else {
                System.out.println("Problem with Deposit");
            }
            }
        }
        if ((char)inData[0] == 'w' || (char)inData[0] == 'W') {
            System.out.print("Enter amount of withdraw: ");
            key = System.in.read(inData);
            if (key != -1) {
            money = Double.valueOf(new String(inData,0,key-1));
            if (myAccount.withdraw(money.doubleValue()) == 0) {
                System.out.println("Withdraw has been made");
            } else {
                System.out.println("Problem with Withdraw");
            }
            }
        }
        }
    } catch (Exception e) {
        System.err.println("Exception thrown");
        System.exit(1);
    }
    }
}

----------------解决方案--------------------------------------------------------
  相关解决方案