Neighbour.java 1.92 KB
package com.lotus.town.neighgour;

import java.math.BigDecimal;

public class Neighbour {
    int id;
    String name;
    int head;
    int jumpCount;
    double money;
    double todayMoney;

    public Neighbour(int id, String name, int jumpCount, int head, double money, double todayMonkey) {
        this.id = id;
        this.name = name;
        this.jumpCount = jumpCount;
        this.head = head;
        this.money = money;
        this.todayMoney = todayMonkey;

        BigDecimal bg = new BigDecimal(this.money);
        this.money = bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
        bg = new BigDecimal(this.todayMoney);
        this.todayMoney = bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    @Override
    public String toString() {
        return "Neighbour{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", head=" + head +
                ", jumpCount=" + jumpCount +
                ", money=" + money +
                ", todayMoney=" + todayMoney +
                '}';
    }

    String getData() {
        return name + "," + jumpCount + "," + money + "," + todayMoney;
    }

    void earn(double monkey) {
        this.money += monkey;
        this.todayMoney += monkey;
        BigDecimal bg = new BigDecimal(this.money);
        this.money = bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
        bg = new BigDecimal(this.todayMoney);
        this.todayMoney = bg.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    String getKey() {
        return String.valueOf(id);
    }

    public String getName() {
        return name;
    }

    public int getJumpCount() {
        return jumpCount;
    }

    public double getMoney() {
        return money;
    }

    public double getTodayMoney() {
        return todayMoney;
    }

    public int getHead() {
        return head;
    }

    public int getId() {
        return id;
    }

}