Rss & SiteMap

课外天地 李树青 http://www.njcie.com

李树青 论坛 南京 财经 课外天地
共1 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:课上讲的银行货币管理程序代码

1楼
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编辑过]
共1 条记录, 每页显示 10 条, 页签: [1]

Copyright ©2002 - 2016 课外天地.Net
Powered By Dvbbs Version 8.3.0
Processed in .04688 s, 2 queries.