以文本方式查看主题

-  课外天地 李树青  (http://www.njcie.com/bbs/index.asp)
--  Java程序语言课件  (http://www.njcie.com/bbs/list.asp?boardid=17)
----  课上讲的银行货币管理程序代码  (http://www.njcie.com/bbs/dispbbs.asp?boardid=17&id=877)

--  作者:admin
--  发布时间:2010/5/5 13:49:33
--  课上讲的银行货币管理程序代码

import java.text.DecimalFormat;

interface ICurrency {
        public double getAmount();

        public void setAmount(double amount);

        public String getType();

        public void setType(String type);
}

abstract class Currency implements ICurrency {
        private String type;

        private double amount;

        public Currency() {

        }

        public Currency(double amount) {
                setAmount(amount);
        }

        public double getAmount() {
                return amount;
        }

        public void setAmount(double amount) {
                this.amount = amount;
        }

        public String getType() {
                return type;
        }

        public void setType(String type) {
                this.type = type;
        }

        public String toString() {
                DecimalFormat df = new DecimalFormat("0000.0000");
                return type + df.format(amount);
        }
}

class Yuan extends Currency {
        public Yuan() {
                setType("Y");
        }

        public Yuan(double amount) {
                setType("Y");
                setAmount(amount);
        }

}

class Dollar extends Currency {
        public Dollar() {
                setType("$");
        }

        public Dollar(double amount) {
                setType("$");
                setAmount(amount);
        }
}

class France extends Currency {
        public France() {
                setType("F");
        }

        public France(double amount) {
                setType("F");
                setAmount(amount);
        }
}

class Action {
        public void transaction(Currency y, double amount) {
                y.setAmount(amount);
                System.out.println(y);
        }
}

public class Exec {
        public static void main(String args[]) {
                Action a=new Action();
                Yuan y=new Yuan();
                a.transaction(y, 1000);

        }

}

[此贴子已经被作者于2010-12-12 08:31:29编辑过]