课外天地 李树青学习天地Java程序语言课件 → 课上讲的银行货币管理程序代码


  共有15571人关注过本帖树形打印复制链接

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

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1940 积分:26616 威望:0 精华:34 注册:2003/12/30 16:34:32
课上讲的银行货币管理程序代码  发帖心情 Post By: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编辑过]

 回到顶部