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

📄 money.java

📁 RMI英文教程,从各个方面教你怎么进行RMI开发
💻 JAVA
字号:
package com.ora.rmibook.chapter13.bank.valueobjects;


import java.io.*;


public class Money extends ValueObject {
    protected int _cents;

    public Money(Integer cents) {
        this (cents.intValue());
    }

    public Money(int cents) {
        super (cents + " cents.");
        _cents = cents;
    }

    public int getCents() {
        return _cents;
    }

    public Money add(Money otherMoney) {
        return new Money(_cents + otherMoney.getCents());
    }

    public Money subtract(Money otherMoney) {
        return new Money(_cents - otherMoney.getCents());
    }

    public boolean greaterThan(Money otherMoney) {
        if (_cents > otherMoney.getCents()) {
            return true;
        }
        return false;
    }

    public boolean isNegative() {
        return _cents < 0;
    }

    public boolean equals(Object object) {
        if (object instanceof Money) {
            Money otherMoney = (Money) object;

            return (_cents == otherMoney.getCents());
        }
        return false;
    }
}

⌨️ 快捷键说明

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