money.java

来自「RMI英文教程,从各个方面教你怎么进行RMI开发」· Java 代码 · 共 50 行

JAVA
50
字号
package com.ora.rmibook.chapter23.rmiiiopaccounts.valueobjects;


import java.io.*;


public class Money implements Serializable {
    protected int _cents;

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

    public Money(int cents) {
        _cents = cents;
    }

    public int getCents() {
        return _cents;
    }

    public void add(Money otherMoney) {
        _cents += otherMoney.getCents();
    }

    public void subtract(Money otherMoney) {
        _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 + =
减小字号Ctrl + -
显示快捷键?